I am attempting to move from the old setup (pre Unity 5.3) where there was always a single scene to embrace the new way of things where multiple scenes can be loaded additively. This seems like it’s going to be useful for us from a development process standpoint so that different people can work on different parts of the scene without having to worry about future merging of files.
What this means, however, is that my nice friendly LoadSceneAsync() call that was working before is no longer going to work in quite the same way and I’m becoming convinced it might not be possible to actually load scenes in the sequence we need them to load. Specifically, I’d like to be able to load all 5 parts of my scene fully in the background, while my loading screen is still animating away, and then once they’re all ready, activate them all so their objects’ Awake() methods all get called in the same frame. This way the sequencing is as similar as possible to the way it used to work and allows things that automatically form links with other elements of the world to continue to do their thing appropriately.
Here’s a simplified version of what I attempted that seemed closest to working as I wanted:
private IEnumerator LoadSequence () {
// Kick off the loading but don't do the activation of any of these scenes yet.
AsyncOperation firstOp = LoadSceneAsync("SceneA", LoadSceneMode.Single);
firstOp.allowSceneActivation = false;
AsyncOperation secondOp = LoadSceneAsync("SceneB", LoadSceneMode.Additive);
secondOp.allowSceneActivation = false;
// Wait until everyone is ready for activation - Unity uses 0.9f as a magic number denoting ready-for-activation.
// BROKEN: This is where things fail - secondOp.progress never goes beyond 0.
// It seems that it can't start its loading until firstOp has been activated.
while (firstOp.progress < 0.9f || secondOp.progress < 0.9f) {
yield return new WaitForSecondsRealtime(0.1f);
}
// Everyone's loaded, let's let everyone activate.
firstOp.allowSceneActivation = true;
secondOp.allowSceneActivation = true;
// May not be necessary?
yield return null;
}
Unfortunately, what happens here is that secondOp’s progress stays 0 forever. Apparently, since firstOp is never allowed to finish its activation the secondOp isn’t ever allowed to load.
Is there some totally other way I’m not seeing to do all the loading THEN all the activation (Awake() calls) at the same time/in the same frame? Is there something I’m misunderstanding about Asynchronous scene loading in Unity? Right now I’ve just fallen back to synchronous loading which makes things generally work, but now my loading screen is very sad and static since it’s sitting there with the main thread blocked.