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
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Package signature validation unexpectedly return an invalid signature status if the validation check is done after the code signing certificate validaty range has passed
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
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.