OnSceneWasLoaded deprecated - cannot find work around
I am following a course that is using Unity 4.6 and they are using the OnSceneWasLoaded event to do stuff.
I've seen the docs here which is saying to now use a delegate :-
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneLoaded.html
However, this is complaining that :-
Cannot implicitly convert type `UnityEngine.SceneManagement.Scene' to `UnityEngine.Events.UnityAction<UnityEngine.SceneManagement.Scene,UnityEngine.SceneManagement.LoadSceneMode>'
The info I've managed to find so far suggests this should work, but struggling to find anything a solution.
using UnityEngine.SceneManagement;
Start(){
SceneManager.sceneLoaded += myDelegateEvent();
}
void myDelegateEvent(){
//DoStuff
}
Am I missing some sort declaration for the delegate?
Answer by hexagonius · Dec 02, 2016 at 04:53 PM
The two problems you have is sceneLoaded is a delegate with two parameters, where you provide none with your myDelegateEvent() method. you need to extend your myDelegateEvent to match the parameters like:
void myDelegate(Scene scene, LoadSceneMode mode){
}
The second mistake is the braces. Adding to a delegate, you only use the method name.
SceneManager.sceneLoaded += myDelegateEvent;
I agree, the docs could be more complete :)
You can also let MonoDevelop help you in these cases. After you've finished typing the += autocompletion should show you some options, with the first one usually the parameter-list need.
Answer by Poon-Moon · Dec 02, 2016 at 05:16 PM
Thanks so much, great answer. Really appreciate your help.
Your answer