- Home /
LoadLevelAsync doesn't work as it should
Hey all. I've tried to use LoadLevelAsync in order to show a loading progress, but unfortunately I don't see any progress. The Editor hangs while loading the next scene for more than a minute because the next scene is huge, and suddenly I get a progress of 1 from 0.
Here's my code:
IEnumerator DisplayLoadingScreen ()
{
progressBar.value = 0;
async = Application.LoadLevelAsync(SceneName);
async.allowSceneActivation = false;
while (!async.isDone)
{
progressBar.value = async.progress;
UpdateText();
if (async.progress >= 0.9f && !async.allowSceneActivation)
async.allowSceneActivation = true;
Debug.Log("I'm yielding at progress: " + async.progress);
yield return null;
}
if (async.isDone)
{
progressBar.value = 1f;
UpdateText();
}
}
The exptected result would be for the Unity editor to not hang, and show a progress of 1...2...3.. etc. Have I done anything wrong?
Thanks for reading.
@pako the while loop is entered. That's why I have the Debug.Log("I'm yielding at progress: " + async.progress); I never said that it doesn't work. I said it doesn't work as it should. I go directly from 0 to 1, waiting for about 1 $$anonymous$$, for a huge scene to load.
Answer by konsnos · Nov 29, 2014 at 12:44 PM
Finally seems there wasn't problem at all. It hanged the Editor, but when built the project ran fine! Just leaving this here in case someone else has the same problem.
Answer by J_Troher · Dec 08, 2014 at 01:31 AM
I'm having the problem, In Editor and In all builds. I have Pro.
IEnumerator LoadLevel(){
AsyncOperation async = Application.LoadLevelAsync ("Map1");
while (!async.isDone) {
loadProgress = (int)async.progress * 100;
LoadingScreen.LoadingText.text = loadProgress + "%";
LoadingScreen.LoadingBar.transform.localScale = new Vector3 (loadProgress, LoadingScreen.LoadingBar.transform.localScale.y, LoadingScreen.LoadingBar.transform.localScale.z);
Debug.Log(loadProgress + "%");
yield return new WaitForEndOfFrame();
}
}
The Debugs don't show up until the new scene loads.. I've even tried packing as much as I can into it to make it require some time to load, thinking maybe I'm just instantly loading.. but idk. Help would be awesome!
Also, I did use the code you posted as well, the only thing different from what I had was that you made use of allow scene activation. I tried with and without. It just chops for a second and switches to the next scene, then sends the debugs...