I’ve been playing around with the SceneManager to see how flexible the async scene loading is and have quickly run into some strange behaviour. The first thing I tried out was loading two scenes asynchronously and then activating one or the other or both. I’m using version 5.3.4f1.
public class RootSceneController : MonoBehaviour {
Dictionary<string, AsyncOperation> preloadingScenes;
void Start () {
preloadingScenes = new Dictionary<string, AsyncOperation>();
PreLoadScene("A");
PreLoadScene("B");
//In this case I'm setting both to activate which works as expected
//Things get weird when the second loaded screen is allowed to activate but not the first
preloadingScenes["A"].allowSceneActivation = true;
preloadingScenes["B"].allowSceneActivation = true;
}
void Update () {
print(preloadingScenes["A"].progress);
print(preloadingScenes["B"].progress);
}
public void PreLoadScene(string sceneName)
{
if (!preloadingScenes.ContainsKey(sceneName))
{
AsyncOperation async = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
async.allowSceneActivation = false;
preloadingScenes.Add(sceneName, async);
}
}
}
When I set ‘allowSceneActivation = true’ on both scenes everything works as expected, both scenes are additively loaded and activated.
Setting ‘allowSceneActivation = true’ on scene A but not scene B also works as expected, scene A is loaded and activated while scene B is loaded and it’s progress value remains at 0.9 (the expected value for a scene that’s loaded but not activated).
However, when I set ‘allowSceneActivation = true’ on scene B but not scene A things get weird. Both scenes load until their progress values are at 0.9 but scene B never activates.
I have tried flipping the orders of the PreloadScene() calls and it seems consistent in that you if you preload two scenes you can’t activate the second loaded scene without having already activated the first.
Does anyone know if this is the expected behaviour or if it might be a bug? I’d like to preload scenes representing areas immediately around the characters current area without knowing which one they might enter, from what I can tell this will prevent me from being able to do that.