how to use LoadLevelAsync to make a progress bar

I want to make my own progress bar when switching between levels in Unity.

I've tried the following code:

IEnumerator LoadLevel1()
{
    AsyncOperation async = Application.LoadLevelAsync("level1");

    while (!async.isDone)
    {
        print(async.progress);
        yield return 0;
    }
}

It doesn't work, and Unity gives the following error message at runtime:

"m_ThreadCheck && !Thread::EqualsCurrentThreadID(m_ThreadID)"

How is LoadLevelAsync meant to be used?

I'm not sure this is actually possible at the moment...

function Start () {
    DontDestroyOnLoad(this);
    print ("Loading...");
    yield LoadLevelWithProgress ("Level1");
    print ("Loading complete");
}

function LoadLevelWithProgress (levelToLoad : String) {
    var async = Application.LoadLevelAsync(levelToLoad);
    while (!async.isDone) {
        print ("%: " + async.progress);
        yield;
    }
}

That works, except async.progress only ever returns 0. You can still have some kind of animated loading indicator, but I don't see how a progress bar is possible, since you never know what the progress actually is. I would guess that's a bug.

After playing with this for a while I discovered that AsyncOperation.progress is in fact functional, however when run in the editor you will never receive the appropriate value from it. In the builds that I have done I have used the progress variable with success to create a progress bar for loading in between levels.

I hope this helps someone.

This is an old post, but I couldn’t find the solution to my LoadLevelAsync problems online and this is one of the first posts that shows up in Google. So I’m just posting my discovery here hoping it’ll help others in the future:

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 somehow, perhaps it accidentally gets synchronized with other things running on that thread) and everywhere else it might not run on the main thread. Update seems to make LoadLevelAsync asynchronous for me … on PC at least, haven’t tested it on other platforms yet.

here’s what you need:

private IEnumerator loadAsync(string levelName)
{
	AsyncOperation operation = Application.LoadLevelAdditiveAsync(levelName);
	while(!operation.isDone) {
		yield return operation.isDone;
		Debug.Log("loading progress: " + operation.progress);
	}
	Debug.Log("load done");
}

async.progress is not functional at this moment. If you look around in other similar questions there’s a confirmation that it’s not implemented even in Unity 3.x

I’ve managed to do this, but I’m guessing that doing a 3D progress bar that reacts to the number instead of writing it on a 3Dtext:

function Start(){
    //Getting the TextMesh on which we're gonna put the numbers in
Loader = gameObject.Find("LoaderText"); 
textMesh = Loader.GetComponent(TextMesh);

    //just making sure we're still downloading
isDownloading = true;
}

function Update() {
    //getting the WWW data from the .js that is actually downloading
loadedbytes = store.GetComponent(storeExtLoad).download;

    //while we're downloading, get the progress bytes loaded, multiply by 100 and round it in order to transform 0.0319 to 32%
if(isDownloading){
	LoaderText = loadedbytes.progress;
	textMesh.text = Mathf.Round(LoaderText*100)+"%";
}
    //when we're done downloading, destroy this instance
if(loadedbytes.isDone) Destroy(me,1);
}

It strikes me you are never leaving the Start method which could result in progress remaining at zero. Shouldn't you put the async in a class variable and do the progress check in an Update method.