I want to instantiate an object into a scene that has been asynchronously additively loaded by the scene manager ( SceneManager.LoadSceneAsync()
). I found SceneManager.SetActiveScene(Scene)
which apparently returns false
if the given scene hasn’t been loaded yet so I thought I’d throw it in a coroutine to just repeatedly set the active scene until it has been loaded. Something like this:
...
SceneManager.LoadSceneAsync("World", LoadSceneMode.Additive);
StartCoroutine(SetSceneActiveDelayed(SceneManager.GetSceneByName("World")));
...
IEnumerator SetSceneActiveDelayed(Scene scene)
{
while(!SceneManager.SetActiveScene(scene))
{ yield return null; }
// Can do my instantiation here
}
However, I found that if I do this repeated check via setting the active scene, the scene that gets loaded in becomes washed out and everything is just fully bright:
OSX Standalone (unexpected result)
It’s the same whether it’s an async load or not. What’s weird is that when run from the editor, it works perfectly fine as long as there were no lights in the originating scene. If there were, the scenes fall back to real-time lighting using both the lights in the original and the loaded scene.
Editor when loaded from scene with lights (also unexpected result)
Is this supposed to happen? How should I find when an asynchronously additively loaded scene has been fully loaded in? I tried OnLevelWasLoaded
but found that it wasn’t getting called.