- Home /
Application.LoadLevelAsync() causes Unity crash?
I'm attempting to use Application.LoadLevelAsync() to load a level and it's causing Unity to crash about 50% of the time. I'm running the load level operation as a coroutine while running a progress bar type object as another coroutine. The level loading operation generates information that updates the progress bar. Has anyone else had a similar experience with Unity crashing when using LoadLevelAsync()?
I haven't... there might be something wrong with the code. Why don't you show us the code so we can debug it.
We would love to see your project in a bugreport so we can fix the crash. (Use inunitymenu->Help->Report a problem). Thanks!
I've come across the same behaviour. I have a GameObject which in it's Start() is attempting to GameObject.Find another object in the scene hierarchy (objects exist in the same scene at design time). However I am seeing that when the on occasions (>50%) that it fails to find the object. And when it fails, I print a dump off all the objects in scene, and notice that they are not all there. This happens on iOS.
The issue turned out to be that one device was network instantiating an object before the other device had finished loading. Because we were loading with LoadLevelAsync, the wrong scene (our loading scene) recieved that object instantiation and because of the GameObject.Find looking for an object in the wrong scene it failed. This was resolved by turning off the message queue before loading and turning it back on after loading was complete ( Network.is$$anonymous$$essageQueueRunning = false; and Network.is$$anonymous$$essageQueueRunning = true; ). There's a great topic at http://unity3d.com/support/documentation/Components/net-NetworkLevelLoad.html
Answer by Max Kaufmann · Aug 02, 2010 at 05:54 PM
Did you PushAssetDependencies() in your build script and forget to load dependent assets?
Answer by neonplaymark · Oct 03, 2011 at 01:42 PM
I had this when a colleague changed the way some scripts worked. He made an object that existed in the scene into a prefab and then used a script to instantiate it. However we had a different script that attempted to GameObject.Find it. On iPhone, the scripts seemed to run in a different order and we only saw this during a LevelLoadAsync. And of course, GameObject.Find returns null if it does not find an object. And you'll get a nasty NullExeceptionError.
With Unity 3.4 you can fix this by setting the Script Execution Order (Edit->Project Settings->Script Execution Order). And make the script that instantiates object run before ones that use the instantiated object.
Your answer
Follow this Question
Related Questions
How to load levels with animation GUI 1 Answer
Preloading scene issue 0 Answers
UI Scene Loading Bar In Unity 5 C#? 1 Answer