- Home /
allowSceneActivation only works once in the editor when trying to delay loading a scene.
I'm trying to delay reloading a level until after I'm done showing some animation. My code is basically:
IEnumerator killPlayer(GameObject player) {
AsyncOperation reload = Application.LoadLevelAsync(Application.loadedLevel);
reload.allowSceneActivation = false;
while (**<some condition>**) {
// Show the player dying, some animation, etc
yield return null;
}
while (reload.progress < 0.9f) {
yield return null;
}
reload.allowSceneActivation = true;
}
As you can see, the key thing is the setting of allowSceneActivation
to false
so that even if the scene is done loading, it won't kill the current scene until eat least after my other animations are done (the first while loop). By the time the first loop is done, the next one potentially waits until we reached the infamous undocumented 90% and only then do I re-enable allowSceneActivation
to finally load the scene.
When I try this in the editor, the first time around it works just fine. But after working once, it never again reloads the scene, because the second while never breaks, because the progress is stuck at 0.
Any thoughts?
Why not remove the second while loop? What's preventing reallowing scene activation as soon as the desired condition is fulfilled?
FWIW, progress being stuck at 0 in the editor seems to be a known bug.
interestingly, I take out the while and it works. So I guess I'll leave it out. The reason why I had the while was cause even at 90% loaded, if I allowed the scene to load I could still tell there was a bit of overhead. But whatever, at least it works. And thanks for the tip on the editor bug.
@saldavonschwartz Have you found a solution to this?
Your answer
![](https://koobas.hobune.stream/wayback/20220613201333im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Got a problem with Async! 0 Answers
LoadLevelAsync multiple pending scenes? 0 Answers
unity LoadSceneAsync works like LoadScene 0 Answers
Trouble With Loading Bar Script C# Unity 5 1 Answer
LoadLevelAsync never executes on a background thread? 0 Answers