I’m very new to unity but I’m working on a function that needs to load another scene and then execute a function in it.
Code looks like this :
public void Respawn()
The problem is that after I load the new scene the second line of code isn’t executed.
The script I’m using is a singleton used for both the scene I’m calling the Respawn function from and the loaded scene.
Instead of calling LoadGame from Respawn() make your MenuManager register a method to the event SceneManager.sceneLoaded. This gets called right after a scene loaded so you can check in your MenuManager method which scene was loaded and call LoadGame accordingly.
//Inside MenuManager class
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneLoaded -= OnSceneLoaded;
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
//Check which scene was loaded using the Scene object and call LoadGame