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
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
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
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.