Search Issue Tracker
Fixed in 5.6.0
Votes
5
Found in
5.4.0b23
Issue ID
810327
Regression
No
SceneManager.SetActiveScene doesn't work inside the SceneManager.sceneLoaded event callback
Steps to reproduce:
1. Open attached "case_810327 repro" project
2. Open "One" scene
3. Play in editor
4. Observe console
Results: SceneManager.SetActiveScene doesn't set active scene on SceneManager.sceneLoaded event callback
Reproduced with: 5.4.0b17, 5.4.0b24
Note: Does not reproduces on Unity 5.3 because SceneManager.sceneLoaded event was introduced in 5.4
Comments (2)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Texture2D hash changes inside of an AssetBundle when rebuilding a SpriteAtlas bundle with an empty AssetPostprocessor Script enabled
- Aniso Level still applies when Generate MipMap is disabled in Texture Import Settings
- Mipmap Limit Groups long names are not truncated when creating a new Mipmap Limit Group with a long name
- “ArgumentException: Invalid double parameter.” error is thrown when Infinity is typed into the Fixed Timestep field
- GameObject becomes gray when using HDRP and STP together on macOS
LeventeSimon
Sep 28, 2016 12:32
Same thing happening in 5.4.0f3. SceneManager.sceneLoaded delegate gets called a frame early.
sramos_eurecat
Aug 24, 2016 11:05
The real issue is that the delegate is called before the scene is actually loaded. The flag "isLoaded" in the Scene received as parameter is still false at this point, and that's why activation is not possible. The flag will be true though by the end of the frame.
As a workaround I am using a coroutine like this:
public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
StartCoroutine(ActivateScene(scene));
}
private IEnumerator ActivateScene(Scene scene)
{
yield return new WaitForEndOfFrame();
SceneManager.SetActiveScene(scene);
}
Anyway I don't see how the callback is useful if we still need to use a coroutine to do this. Imo it doesn't make much sense and I would rather be notified after loading has completed. If there is any other use case in which being notified beforehand is useful, I would really like to know. In the meantime I'm upvoting this issue.