After loadlevelasync, will AsyncOperation be isDone at least one frame?
I am wondering, if I use SceneManager.LoadLevelAsync, and check for AsyncOperation.isDone, can I be sure that isDone will be true at least one frame before the current scene gameObjects are destroyed and the new scene is effectively loaded?
Or at least, can I be sure that there will be at least one frame with let's say, a AsyncOperation.progress of 0.9 or more? Even for example in case of very performant devices.
I would like to execute something just before the current gameObjects of the current scene are destroyed, and if possible, without using DontDestroyOnLoad. And AsyncOperation.allowSceneActivation is true. Thank you!
Answer by agentc0re · Jan 16, 2017 at 02:32 AM
You could use AsyncOperation.Progress to check how much of the level has been loaded by loadlevelasync and then when it reaches, say 90%, you could do what code you want to do and then let it resume there after.
I've done something similar in the past: I modified it for your scenario a bit. :D
IEnumerator AsynchronousLoad(string scene)
{
yield return null;
AsyncOperation ao = SceneManager.LoadSceneAsync(scene);
ao.allowSceneActivation = false;
while (!ao.isDone)
{
if (ao.progress == 0.9f)
{
ao.allowSceneActivation = true;
//Do your other stuff too.
}
yield return null;
}
}