- Home /
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;
}
Answer by Bunny83 · Sep 29, 2015 at 02:34 PM
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.
would you agree it is simply not possible to use allowSceneActivation
with LoadSceneAsync
??
You'd think this pattern would work perfectly:
Debug.Log("about to load!");
AsyncOperation a;
a = LoadSceneAsync("HugeScene");
a.allowSceneActivation = false;
while (!a.isDone)
{
Debug.Log("loading " +a.progress.ToString("n2"));
yield return null;
}
Debug.Log("loaded!!");
a.allowSceneActivation = true;
but it simply does not.
It can't be that hard to
begin loading
wait until it's all loaded
then activate it
Strange stuff. Is the idea that you in fact must use additive, and then manually UnloadScene
of he one you were just in?
(Note I talk only of simply loading one new scene: not multiple scenes as addressed in your A.)
Answer by Kyle_WG · Sep 29, 2015 at 12:52 PM
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.
That's not the problem though, the problem is that the scene never activates. How do I activate the scene?
Hmmm.. I do it with LoadLevelAsync (setting sync.allowSceneActivation = true;). Change to non-additive for now to see if it works. If it works then it's Unity's LoadLevelAdditiveAsync's problem. What Unity version are you working with? Apparently 5.2 has fixed some of these problems as they're aware of it.
Also try removing all the lines that set async.allowSceneActivation; to see if that bypasses the error.
I'm using 5.2. async.allowSceneActivation set to true initially bypasses the error, but that means I cannot decide when to activate the scenes myself. The error only happens second time I try to load the scenes (after having all of them unloaded).
Your answer
Follow this Question
Related Questions
LoadLevel Async 2 Answers
How to load scene when async.progress is 0.9? 0 Answers
Odd behaviour when preloading multiple scenes 1 Answer
How to make functions async? 2 Answers
Two async operations at the same time not working ? why ? 0 Answers