I am having trouble getting LoadLevelAsync to work correctly. For some reason it seems to act just like LoadLevel. The loading time is almost the exact same and when the user clicks on the gui to pick which level to load next it freezes all movement while it attempts to load the next level. All I need is for the user to be able to continue walking around the scene while the next scene is loaded. Loading time isn’t as important. Here is a small snippet of my code, and I just can not figure out what the problem is.
IEnumerator LoadLevel(string name) { yield return new WaitForSeconds(1.5f); //nextLevel is one of the class fields nextLevel = Application.LoadLevelAsync(name); while (!nextLevel.isDone) { yield return 0; *} * }
I discovered that LoadLevelAsync behaves like LoadLevel depending on which thread it’s running.
Unity has this nasty undocumented behavior that in Start/Awake it’s running on the main thread (which makes LoadLevelAsync behave like LoadLevel) and everywhere else it might not run on the main thread. Update seems to make LoadLevelAsync asynchronous for me … on PC at least.
While you’re waiting for your level to load your coroutine is just returning 0 constantly. The loading is not what is slowing your program it is this loop.
Instead of yield return 0, use yield return new WaitForEndOfFrame()