Additively loaded scene gets stuck at 90% even if allowSceneActivation is true.

I am basically loading 3-4 scenes at the same time additively and want to activate them simultaneously using another game object. What I get is just my console spammed with:

"Progress: 0.9, true"

… and none of my scenes are activated. It looks to me as if Unity cant handle multiple async operations. Or am I doing something wrong?

The component which does the loading looks like this (and then I just set “activateScenes” to true from another object):

public bool activateScenes = false;

public void Start(){
     StartCoroutine(LoadSceneAdd("Scene1"));
     StartCoroutine(LoadSceneAdd("Scene2"));
     StartCoroutine(LoadSceneAdd("Scene3"));
     StartCoroutine(LoadSceneAdd("Scene4"));
}

private IEnumerator LoadSceneAdd(string name){
     AsyncOperation async = Application.LoadLevelAdditiveAsync(name);
     async.allowSceneActivation = false;
     while(!activateScenes)
     {
              yield return null;
     }
     async.allowSceneActivation = true;
     while(async.progress < 0.999999f)
     {
              Debug.Log("Progress: " + async.progress + ", " + async.allowSceneActivation);
              yield return null;
     }
     Debug.Log("Scene activated!"); // The code never gets here.
     yield break;
}

The async operation represents the whole level loading procedure. IsDone will become true when the loading is “really” finished. That is when the objects of the scene have been activated. That this point where progress will be 1.0 as well.

important:

  • You can load multiple levels but you have to activate them in the same order. So if you load Scene1 followed by Scene2 you can’t activate Scene2 until Scene1 has been activated.
  • Make sure you never (ever) load a scene with “allowSceneActivation = false” and never activate it. It will block the loading queue. When you “loose” the reference to the pending AsyncOperation, there’s no way to recover it’s functionality besides a game restart.

As long as you activate them in the same order that you loaded them it should work just fine.
I’ve made a webplayer example (you need a browser that still supports NPAPI). I’ve included a link to the only script involved at the bottom of the webplayer page. It’s located in the “loader” scene.

When you press the “Load” button it requests Scene1 to Scene4 but sets “allowSceneActivation” to false. Try activating them manually from the bottom to the top. No scene will be activated until the first loaded scene is activated.

As you can see i “disabled” the delete button to ensure you can only remove a level load task from the list when it has been activated.

(ps: I tried building for WebGL but (it feels like) it takes 20x the build time and the final product doesn’t seem to run in my FireFox. So i stick to the webplayer ^^).

pps: I currently use Unity 5.1.1f1.

Yeah it never fully reaches 1. (Usually 0.9f)
Check the flag async.isDone instead.
If you’re reporting to the user too just use multiply by 100 and use the Mathf.Ceil. You’ll get a nice percentage.