LoadLevelAsync is acting like LoadLevel

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.

void OnGUI()

{

    Rect[] guiRects = {Rect1, Rect2, Rect3, Rect4};
    string[] configNames = {"Level1", "Level2", "Level3", "Level4"};

    for(int i = 0; i < guiRects.Length; i++)
    {
       if(GUI.Button(guiRects_, configNames*))*_

StartCoroutine(this.LoadLevel(configNames*))*
}

}

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 (!nextLevel.isDone)
{
yield return 0;
}

This line here might be the problem, I think you’re pausing the application in the while loop.

Looking at the docs(http://docs.unity3d.com/Documentation/ScriptReference/Application.LoadLevelAsync.html) you may want to try something like this

AsyncOperation async = Application.LoadLevelAsync("MyBigLevel");
yield return async;

And just to make sure, async operations are unity pro only, so make sure you have unity pro setup.

I’ve wrote this maybe it could help you : (in C#)

void OnGUI()
	{
		if(async != null)
		{
			loadingComplete = async.progress;
		}
		else
		loadingComplete = 0;
		GUI.DrawTexture(new Rect(0, 0, Screen.width * (loadingComplete), 50), Texture2D);
	}

	IEnumerator waitAsecond (float waitTime) 
	{
		yield return new WaitForSeconds (waitTime);
		StartCoroutine(Load ());
	}

	IEnumerator Load () 
	{
		async = Application.LoadLevelAsync("###");
		async.allowSceneActivation = false;
		yield return async.isDone;
		yield return loadingComplete = 100;
		SwitchScene();
	}

        private void SwitchScene()
	{
		if (async != null)
			async.allowSceneActivation = true;
	}

I still have a freeze but it’s the best I could do, so if someone found a better way I’m interested !!!

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()

I’ve tried all of these answers and none of them work for me. lol. Also Using Pro.