- Home /
Loaded two scenes asynchronously, neither will activate?
After I do this:
this.operation = SceneManager.LoadSceneAsync("Scene_A");
this.operation.allowSceneActivation = false;
this.operation = SceneManager.LoadSceneAsync("Scene_B");
this.operation.allowSceneActivation = false;
yield return new WaitForSeconds(5f);
this.operation.allowSceneActivation = true;
I expect Scene_B to load when it's ready. However that scene does NOT activate. There are no errors in the console and the currently-loaded scene stays loaded. It's as if no code ran at all (I debugged through it and confirmed that all lines execute). I've also confirmed that Scene_B loads fine when loaded synchronously.
What am I doing wrong, here? Is pre-loading two scenes and then later deciding which to activate not supported?
Answer by IgorAherne · May 01, 2018 at 04:04 AM
yes, you can file a bug report to Unity. I did and they said "Not enough inscentive to re-program our system" to allow for such an instant activation. Also, Monobehavior.Start is not conforming to execution order, regardless of the order in which you activate your scenes, unless you do it like me in the code below:
My code suffices like so:
using System.Linq;
private List<AsyncOperation> _loadingOperations = new List<AsyncOperation>();
IEnumerator LoadUp_ThisCrap(List<string> sceneNames){
foreach(string sceneName in sceneNames) {
AsyncOperation oper = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
oper.allowSceneActivation = false;//scenes will be activated after all loaded.
_loadingOperations.Add(oper);
}//end foreach
while (true){
float progress_01 = _loadingOperations.Average(oper=>oper.progress);
if(progressFunction != null) { progressFunction(progress_01 / 0.9f); }//issue callbacks to anyone interested
if(progress_01 > 0.9f){ break; }
yield return null;
}//end while
//all scenes loaded, now activate them in the order they were supplied:
for(int i=0; i< _loadingOperations.Count; ++i) {
AsyncOperation oper = _loadingOperations[i];
oper.allowSceneActivation = true;
yield return oper;//<-- wait for it to complete, because unity will screw up activation order
}
}
Your answer
Follow this Question
Related Questions
Loading scene with LoadSceneAsync freezes and progress jumps from 0% to 90% 2 Answers
SceneManager onActiveSceneChange Pause for a while before loading a new scene 0 Answers
WebGL missing function pthread_create? 1 Answer
AsyncOperation activating immediately even with async.allowSceneActivation = false; 0 Answers
How to call NetworkClient.Ready() ? 1 Answer