x


Application.LoadLevelAsync not working in Unity 3.3 Pro?

Hi everybody,

I've been looking for some answers for a moment now, and a lot of people seem to have this problem, but I never found any correct answer to that.

Basically I just use the code found on the Application.LoadLevelAsync doc page

AsyncOperation async = Application.LoadLevelAsync("MyBigLevel"); yield return async; Debug.Log("Loading complete");

It does load the level correctly, but it actually doesn't do anything different than the simple Application.LoadLevel; by this, I mean that I'm willing to have a user-friendly animation playing while my level is loading, and it doesn't. Even using the asynchronous loading, the scene just freezes until the new one is loaded.

In addition, I want to state that no, the scene being loaded is not heavy at all, so it can't come from a long initialization post level loading.

As stated earlier, a lot of people are complaining about that and there is never any answer given, so is it just a bug of Unity's last version or what?

Thanks.

more ▼

asked Apr 05 '11 at 04:05 PM

Thomas 6 gravatar image

Thomas 6
46 1 1 4

Have you, by any chance, found a solution to this issue? - plus, postouros related: http://answers.unity3d.com/questions/61598/how-to-preload-a-scene-with-progress-bar-so-it-can.html

Oct 10 '11 at 05:36 PM Cawas
(comments are locked)
10|3000 characters needed characters left

6 answers: sort voted first

Mine seems to work fine and I am on iphone, but I have all the gameObject's turned off in the next scene so as not to fire the Start() on all their scripts which have heavy work loads.... Here is how I do it, where LoadingScreen has a bunch of animated sprites

    // call back from a button
public void AcceptMission()
{   
    LoadingScreen.gameObject.SetActiveRecursively(true);
    SettingsPanel.gameObject.SetActiveRecursively(false);               
    MissionScreen.gameObject.SetActiveRecursively(false);               
    AcceptMissionScreen.gameObject.SetActiveRecursively(false); 
    StartCoroutine(LoadHangarAsync());
}   

    private AsyncOperation LoadingHangarOperation;
IEnumerator LoadHangarAsync()
{
    yield return new WaitForSeconds(1.5f);
        LoadingHangarOperation = Application.LoadLevelAsync("HangarRetina");
    while (!LoadingHangarOperation.isDone)
    { yield return 0; }
}
more ▼

answered Apr 05 '11 at 04:10 PM

Jeston gravatar image

Jeston
419 27 31 34

Still not working... The only difference between yours and mine at the moment is that you turn off the gameobjects of the next scene; so I guess the problem comes from here. Though in that case I don't see the point of LoadingLevelAsync() as you actually do all the loading (understand here the activation of your gameObjects that you turned off) afterwards, which just delay the problem. Furthermore, in order to do that, I would have to create all my objects from my next scene into my menu scene, in order to be able to deactivate them, and thus would have a heavy loading at he app start...

Apr 06 '11 at 07:45 AM Thomas 6

Unlike with Thomas, this solved my issue!! We replaced yield return async; for the line here advised while (!async.isDone) { yield return 0; } and unity stopped crashing!!! Thanks, Jeston!

Mar 07 '12 at 07:13 PM Cawas

Seriously... the whole engine stopping while LoadLevelAsync is loading my next level is driving me insane. Has anyone found a solid answer for this? It seems like all these discussions just fizzle out.

Here are the specifics of my case:

  • Using Pro

  • Running on Android

  • Don't have anything heavy in any of the start/awake functions of the scene being loaded

  • The old scene (with a progress meter, reading off the progress of the async operation), as expected, is still loaded while the async operation is underway, The progress meter, however, practically stops at like three frames per minute.

  • I put a debug.log msg on Update(), just to see what was going on... it ran about seven times, sporadically, during the ~30 second load.

  • I tried, as suggested, using

while(!asyncOpLvlLoad.isDone) { yield return 0; }

as opposed to just yielding the async op. No luck.

I'd really appreciate any help with this, what a pain in the butt.

Aug 27 '12 at 11:49 AM rbisso

Thank you for the trick sir!! but my problem is that the application kind of "Lags" when using the LoadLevelAsync... It feels like just using the normal loadlevel.

when I check the "progress", it always logs "1" no luck of using it to Lerp the position of my progress bar.. :(

Jan 20 at 11:21 AM vanofthedawn12

@vanofthedawn even in Unity4, loadlevelasync doesn't work on Editor. Compile and test it, it should work.

Jan 21 at 01:13 PM Cawas
(comments are locked)
10|3000 characters needed characters left

Well, i haven't used Application.LoadLevelAsync yet, but the only thing that comes to my mind is that you forgot to mark your GameObject with DontDestroyOnLoad. When the loading is finished it will destroy all objects that are not marked with DontDestroyOnLoad and therefore your coroutine will just be erased. Don't forget that coroutines run on a MonoBehaviour-script instance. If the script is destroyed the coroutine will be removed as well.

more ▼

answered Oct 10 '11 at 05:49 PM

Bunny83 gravatar image

Bunny83
46.9k 12 50 210

This is a great insight, but I'm having a very similar issue as Thomas and even usin DontDestroyOnLoad won't make my animation run nor even debugging messages appear properly while loading.

Oct 10 '11 at 06:04 PM Cawas
(comments are locked)
10|3000 characters needed characters left

It's been a few years since you asked, but just in case someone is still looking:

http://answers.unity3d.com/questions/338000/the-solution-to-asyncoperationprogress.html

This page solved the problem. The issue is that AsyncOperation.progress can get rounded to 0 or 1 unless handled carefully. The person in the link simply multiplied the value by 100f.

Cheers. -Ryan

more ▼

answered May 21 at 08:23 PM

ryanmillercg gravatar image

ryanmillercg
112 1 1 4

Thank you, Ryan!!! I'll give this a shot, it still wasn't working for us.

May 21 at 08:25 PM rbisso
(comments are locked)
10|3000 characters needed characters left

I am searching the answer anywhere, but get nothing now, waha

more ▼

answered Oct 20 '12 at 09:06 PM

wushuang212 gravatar image

wushuang212
1

(comments are locked)
10|3000 characters needed characters left

I agree! I've tried to track the progress of the AsyncOperation and it goes from 0 straight to 1. I have a bigger scene that I am trying to load. There's no way an async load on it should go from 0 to 1. Anyone know what's going on here?

more ▼

answered Apr 12 '11 at 08:11 PM

Varnae gravatar image

Varnae
1

Jumping from 0 to 1 has been a known bug since like v2.6, it still loads the level, just doesn't accurately report the normalized progress. This pretty much kills the ability to do progress bars, but the isDone property will be accurate in reporting that the async operation finished. ==

Apr 12 '11 at 08:27 PM equalsequals

Well it seems to me that instead of just killing the ability to do progress bars, it's killing the entire concept of asynchronous as in the end it just does the same thing as the usual LoadLevel() (unless there is something I missed)

Apr 13 '11 at 07:22 AM Thomas 6

I have also found this to be the case. Is it reported as a bug?

Oct 21 '12 at 06:39 PM rbisso
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3935
x529
x183
x25

asked: Apr 05 '11 at 04:05 PM

Seen: 5425 times

Last Updated: May 21 at 08:25 PM