LoadLevel Async

I am toying with Load Level Async but it isn’t quite what i expect. I will give you an example of how I want to apply it and for what purpose.

For example I have a start screen with Play Game, Help etc. What i would like to do is start loading the first level in the background so that when they click play game it’s already loaded.

The problem at the moment is with my limited knowledge of async as soon as it loads the level the game starts playing, regardless of whether they have clicked play. I could put a boolean in to check and see if they have clicked play before loading the level but that obviously doesn’t fix the problem because then it will still take the same amount of time to load as it would normally.

For further application when you reach the end of the level i have transmissions from an NPC that explain what the next level is all about and if i can’t i might as well start loading the next level while they are reading. How can i achieve this.

At the moment i am using the following:

function Start () {
    
    var async : AsyncOperation = Application.LoadLevelAsync ("level1");
    yield async;
    Debug.Log ("Loading complete");
}

Can I achieve what i want using loadLevelAsync or do i need to use something else?

I asked the same question recently:

Basically, you can’t use loadLevelAsync.

You can try using loadlLevelAsyncAdditive and have your next level start completely disabled and then use some sort of levelManager to enable gameObjects in the new level as and when you pleased. You would probably also have to use it to kick off destruction of the objects in the old level.

You could also try using AssetBundles as suggested in the answer to the question I posted.

Don’t know if its new to Unity 4.0 but…
**** NOTE *** If you press the STOP button in the editor, AFTER you already called loadLevel() Unity will freeze until you load the level completely

this works:

public class loadLevelAsync{
    public static AsyncOperation async;
    
    public void loadLevel(){
    	async = Application.LoadLevelAsync("MyBigLevel");
    	async.allowSceneActivation = false;
    }
    
    public void startLevel(){
    	async.allowSceneActivation = true;
    	async = null; //because I made it a static member
    }
}