- Home /
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
Answer by Jeston · Apr 05, 2011 at 04:10 PM
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; } }
Still not working... The only difference between yours and $$anonymous$$e 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...
Unlike with $$anonymous$$, 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!
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 $$anonymous$$ute.
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.
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.
Answer by Bunny83 · Oct 10, 2011 at 05:49 PM
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 $$anonymous$$ and even usin DontDestroyOnLoad
won't make my animation run nor even debugging messages appear properly while loading.
Answer by ryanmillerca · May 21, 2013 at 08:23 PM
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
Thank you, Ryan!!! I'll give this a shot, it still wasn't working for us.
Answer by Varnae · Apr 12, 2011 at 08:11 PM
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. ==
Well it seems to me that ins$$anonymous$$d 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)
I have also found this to be the case. Is it reported as a bug?
Answer by wushuang212 · Oct 20, 2012 at 09:06 PM
I am searching the answer anywhere, but get nothing now, waha