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.

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

6 Answers

6

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; }
}

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!

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.. :(

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

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.

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.

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

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

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

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?

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. ==

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

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

Comment you question insted of add this as an answer. It's aint no forum.

LoadLevelAsync do not create any type of loading animation in any Unity version, you have to create it yourself.

I believe the OP is attempting to create his own loading animation and LoadLevelAsync is not allowing that animation to run as it should... LoadLevelAsync is stopping the user-created animation from running because it's not behaving as if it's actually asynchronous.

No, I think he misunderstood the whole Async concept.

You should ask him directly. I'm having the same exact problem he's describing, where the scene with my loading animation is freezing up while the next level is supposedly loading asynchronously. I believe you are misunderstanding the way he is phrasing his question. The question is valid, though.