How do I get Asyncoperation to yield?

I have this code in my start method:

        aSync = new AsyncOperation[2];
	    aSync[0] = Application.LoadLevelAsync(2);
        aSync[1] = Application.LoadLevelAdditiveAsync(3);

I would like the loading process to not switch over to the next scene until both have loaded. Right now, it loads right after 0 is done and for a brief moment, async[1] isn’t loaded so you can see through everything.

So how do I get the ASyncOperations to yield until they are done or until the player taps the screen or something?

There is nothing you can do aside of showing a loading screen at the start of level 2 which vanishes once the loadleveladditve async has taken place. Though if you want to wait for it anyway, I wouldn’t use an async anymore, just use the normal one and make it wait behind the load screen, as thats much faster.

What you can not do is syncronize the two and you really don’t want to. Because if loadleveladditive would start in the current level (which can happen if they ended the same moment), you would at worst even kill its additive load with the switch as it won’t carry over to another scene and stuff like that

Thanks for the quick response but I have another question. I don’t quite understand what you meant in the bolded area. How would I have a normal loadlevel wait behind the load screen? Doesn’t that defeat the purpose of ASync if you can make that one yield and not async? Also, how do I get normal loadleveladditive to wait?

No.

What I would do is:

  1. Use LoadLevelAsync to load into the new level unblocking.
  2. When there, show a load screen and do LoadLevelAdditive, without the async.

LoadLevelAdditive itself is blocking if its not async, so it would wait automatically. The load screen would just be to prevent the user from realizing that it is blocking.

The problem here is that you combine two things that are not really designed and meaningfull when combined.
Cause either you want to load additional level content, or you want to switch to a new level so you would only use one of the two.

Why are you using the load level + straight load level additive? couldn’t you add the additive to the other level right out of the box or load both additively?

I’m not too familiar with the workings of loading levels and such (I just got Unity Pro, so I haven’t had too much time to play with it). I use loadlevelasync to load my global objects (character, enemies, main camera, GUI) and then use loadleveladditiveasync to load level specific objects (actual level, ground items, A*). I don’t want them to be together because I want to be able to remove the level specific objects and add loadleveladditiveasync in the new level objects when a player reaches an edge of the level (I’m doing something similar to what Zelda does with the scrolling map sections due to A* constraints).

I will try what you said though as it doesn’t sound too difficult. When I boot up the loading screen, I will loadleveladditiveasync the levelspecific objects (so the loading screen is still there), then I will loadleveladditiveasync the global objects and remove the loading screen when they are booted up. That should work… Is that along the lines of what you were trying to tell me to do?

I’m not sure I really get how your code is built so I can’t give good advice here.

the loadleveladditiveasync for the characters sounds bad for example as you likely have them already and will keep them a while (while you remain in the current environment / dungeon) while the loadleveladditiveasync for the new “screen” would work but you would likely do it for all surrounding screens you can reach from the current one as you reach the current one so they are prepared upfront and then unload them again later as you move to a new screen and know for sure they aren’t required anymore.

also A* should really not have much trouble with zelda style screens normally as they are barely 200 grid points normally, if we went back to the NES originally it would be barely 40 :wink: