Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411412 Posts in 69360 Topics- by 58415 Members - Latest Member: sophi_26

April 15, 2024, 11:11:49 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Please help me understand SceneManager.sceneLoaded!
Pages: [1]
Print
Author Topic: Please help me understand SceneManager.sceneLoaded!  (Read 3832 times)
darkhog
Level 7
**


Dragon Agent


View Profile
« on: August 29, 2016, 07:46:51 AM »

I had to upgrade to 5.4 because of the performance improvements it brought back. Unfortunately code I'm using, both first and third party that I can't upgrade to the "compliant" versions due to compatibility issues, is using OnSceneWasLoaded which has been deprecated.

Unfortunately I don't understand SceneManager.sceneLoaded as the docs only explain what it does. I know (and use) delegates, but some delegates have to take parameters while others don't. I don't know which parameters sceneLoaded needs to have (if at all). The docs only say this: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneLoaded.html

No example code, nothing. Please help.
Logged


Be a computer virus!


I cannot C well, so I stick with simpler languages.

There are no impossible things, there is only lack of skill.
0xDEADBAAD
Level 0
**

Hooker with a penis


View Profile WWW
« Reply #1 on: August 29, 2016, 07:55:52 AM »

Are you looking for this?



If not, I didn't quite get your question Tongue
Logged
darkhog
Level 7
**


Dragon Agent


View Profile
« Reply #2 on: August 29, 2016, 08:30:33 AM »

Yes, yes. Didn't show up in monodevelop for some reason. Anyway, the way I want to fix this in the code is to rename OnSceneLoaded in the files so the warning won't show up, then add delegate function that would call old (now renamed) OnSceneLoaded and add delegate in the Awake().

Does that sound right? Do I have to also remove delegate in OnDestroy or something or will unity take care of it? Last thing I want is multiple delegates to run at the same time or a memory leak of some sort.
Logged


Be a computer virus!


I cannot C well, so I stick with simpler languages.

There are no impossible things, there is only lack of skill.
0xDEADBAAD
Level 0
**

Hooker with a penis


View Profile WWW
« Reply #3 on: August 29, 2016, 08:57:58 AM »

My first guess is that you should remove the delegates in OnDisable(). Otherwise, you'll keep a reference to every object that has subscribed to SceneManager.sceneLoaded.

But since it is a UnityAction and not a standard Action, perhaps there's some magic to prevent this from happening.

I wish I could tell you but I haven't used UnityEvents so far.

I'd unsubscribe in OnDisable() anyway just in case.
Logged
darkhog
Level 7
**


Dragon Agent


View Profile
« Reply #4 on: August 29, 2016, 10:57:29 AM »

Okay, thank you!
Logged


Be a computer virus!


I cannot C well, so I stick with simpler languages.

There are no impossible things, there is only lack of skill.
raigon
Level 0
*


View Profile
« Reply #5 on: July 02, 2019, 04:17:13 PM »

looking at the required signature
SceneManager.LoadScene requires you to subscribe to a method that contains the following formal paramaeter

Scene and LoadSceneMode


public static event UnityAction<Scene, LoadSceneMode> sceneLoaded;


ex
SceneManager.sceneLoaded += MyMethod


MyMethod(Scene currentScene, LoadSceneMode mode)
{

//code
}

you always want to subscribe in OnDisable and OnDestroy
 
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic