- Home /
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?
Answer by HazeTI · Apr 17, 2012 at 02:48 PM
I asked the same question recently: http://answers.unity3d.com/questions/238015/is-it-possible-to-use-loadlevelasync-and-the-wait.html
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.
That's ridiculous... can't believe that.
$$anonymous$$oving on from my disbelief. Could you briefly describe AssetBundles just to give me somewhere to start from in my own research?
Cheers.
I know...
I'm afraid I can't help you with AssetBundles, I've not used them myself. Try forums/wiki/answers/google.
I have had a thought. I am just going to do a seperate scene that has nothing on it but a gui texture saying loading. So you click play level, it takes you to the loading level scene which asyncs the next level. That way it will be very quick to load the level load scene and then the player will be aware that the game hasn't frozen it's just loading. All i really need to figure out is a level manager script so that the level loading scene knows what level you have come from and then which one to use.
So the script would have a don't destroy on it and when you click next level it adds to an int and then the script will know what level to load next.... Sounds good in theory.
Yup, we've pretty much done just that. Still, it's annoying that the level loading can't be started before hand and then Unity be told when to make the actual switch.
It seems SO simplistic! Why the hell not!?
I have just whacked that out and it's working brilliantly, only problem is that it murders the Flash Export... extremely frustrating waste of time! But there you go.
Hopefully they will sort it out eventually.
Thank you for your help. Have some $$anonymous$$arma.
Answer by kramcomposer · Feb 20, 2013 at 04:48 PM
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
}
}
so I tried that exactly and when I execute "async.allowSceneActivation = true;" anywhere Unity freezes completely and I have to restart it.
What Unity version are you using and how are you calling the method?
thanks for a lead on this strea$$anonymous$$g issue :)
I'm using Unity Pro 4.0.1 PC version. Be sure you Level is added to the build. and first I call loadLevel() method, I do some things that take awhile like 3-4 seconds plus, then I call startLevel() ..
BIG NOTE * Unity Editor will Freeze / Crash if you press the STOP button once you've started the AsyncLoadLevel, meaning.. once you have started the loading of the level, you need to let it finish, and load that level, or Unity will freeze if you try to Stop playback
Your answer
Follow this Question
Related Questions
Asyncchronous image loading 2 Answers
How to load scene when async.progress is 0.9? 0 Answers
Load menu via SceneManager 0 Answers
LoadLevelAsync - Stops Randomly? 1 Answer