- Home /
Odd behaviour when preloading multiple scenes
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.
Answer by WillTM · Jun 17, 2016 at 04:05 PM
I'm pretty sure that is expected behavior, run a search for 'async loading stuck at 0.9 ( 90%)' or something similar, I think i've read setting allowSceneActivation = false will stall the load process completely ( for other scene loads aswell) until the stalled scene has been allowed to finish loading i.e had allowSceneActivation = true , and finished that last bit. then it will continue with the second load operation.
Your answer
Follow this Question
Related Questions
Loading scene with LoadSceneAsync freezes and progress jumps from 0% to 90% 2 Answers
AsyncOperation activating immediately even with async.allowSceneActivation = false; 0 Answers
Two async operations at the same time not working ? why ? 0 Answers
Can't access AsyncOperation instance to change allowSceneActivation 2 Answers
SceneManager.LoadScene used within promise (or async callback) does nothing 0 Answers