- Home /
Unity takes forever to load scene
Using Android 2.3.x, 512 MB of memory
I have a mobile game that has a couple of scenes. I can load each scene and play the game for a while. But if I continue to reload scenes/levels. The game will eventually hang, and never finish loading the next scene.
I removed every script incase I had a memory leak or reference issue. But it still hangs. When it is "hanging", logcat spams this:
E/Unity ( 7659): Inflate Error: invalid code lengths set
E/Unity ( 7659):
E/Unity ( 7659): (Filename: ./PlatformDependent/AndroidPlayer/ZipFile.cpp Line: 234)
E/Unity ( 7659):
E/Unity ( 7659): Inflate Error: invalid code lengths set
E/Unity ( 7659):
E/Unity ( 7659): (Filename: ./PlatformDependent/AndroidPlayer/ZipFile.cpp Line: 234)
E/Unity ( 7659):
E/Unity ( 7659): Inflate Error: invalid code lengths set
E/Unity ( 7659):
E/Unity ( 7659): (Filename: ./PlatformDependent/AndroidPlayer/ZipFile.cpp Line: 234)
E/Unity ( 7659):
Looks like a Unity error related with loading assets.
I will receive low memory warnings before the hang happens. I check the memory left and it seems like I have alot left (100+ MB?). Maybe there is a buffer overflow somewhere? So far my best solution is to combine every scene and remove every non-essential asset (Or else I will run out of memory), so I never have to reload a scene. But I don't think I should have to do this. I tried the empty scene as a loading screen idea but that had no improvements. If I remove assets (textures, meshes, etc) from the scenes. I can reload the scenes many more times. But it doesn't matter what's in the scene. A crash is guaranteed.
I made a test project, included a empty loading screen scene and a basic scene with a textured cube. After a while, the scene will fail to load and Unity won't do anything but spam that error, the only thing I am able to do is to kill the process (or quit application). I can only kill the process if Unity is trying to loading asynchronously, if loading scene normally, the game will seem like it is frozen.
I do not believe that I am the only person in the world that has encountered this problem. But I am also completely lost and have no idea where to go from here. Any ideas? (Even accepting crazy ideas at this point!)
I've just run into this same issue, did you guys ever find a solution for this? I'm using the exact same platform (Android 2.3.x 512$$anonymous$$B).
At first I thought it was an error in my scripting and looked for something going wrong in the Async loading, but no errors were being thrown and it just seems to hang with the async operations '.progress' value holding on a certain percentage and the '.isDone' value always returning false.
But I started looking deeper and found much of the same behaviour and then came across your post. Were you guys able to work it out?
Thanks for any help.
Never actually solved the issue, but I did discover a messy work-around. I'm still not 100% on what the problem is, while researching I discovered that the memory heap can get fragmented and then after so many loads, your game may hang. So what I did was $$anonymous$$imize all loading. I jam-packed as much as I could into one scene, loading some extras additively. Now when I need to load a new scene, I just LoadLevel my giant scene and I have a script that toggles chunks on/off depending on what game level I want to load. I find this doesn't really unload/load anything, more or less resets the current scene. Like I said, it's messy. I basically load everything once and hide it, or as much as I can before the game crashes on the first load. I don't like this method, but this is the best solution I have found so far... Hope this helps. Let me know if you find anything :)
Edit: Also reducing the amount of memory required for the entire game/per scene helped get more loads in before it ultimately hangs itself.
Hey thanks for the quick reply! Yes this has definitely helped out thanks :D
$$anonymous$$emory heap can get fragmented from loads, cool I'll keep researching too. I see what you mean that does make sense to avoid level loading where possible too.
And I agree that less memory helps out, I'm working on a test project with 3 levels at the moment where the first 2 levels are quite small and the third level is a big one, and more often then not the third level will usually be where it hangs.
Do you think using 'additive' level loading may remove the problem? Because one thing that I was thinking it might be is normal level loading handling both unload and load processes that overlap; like the unloading and loading code is trying to access the same operations from Android at the same time and ending up waiting forever for each other
I might test this out by manually Destroy()ing objects of the previous level and then try to load the next level with additive loading.
I might call it a day here though for me, but I'll be back onto this tomorrow so I'l let you know for sure if I find out anything new.
Thanks a lot for the feedback Jessespike, this one is a real headache :S
Answer by goodhustle · Sep 14, 2012 at 12:07 AM
Looks like a bug, send in your test project and see if they can track it down.
Your answer
Follow this Question
Related Questions
Webplayer hangs on loading scene 2 Answers
I cant load my scene? 0 Answers
The best way to load scenes ingame 3 Answers
Unity crashing when loading scene 1 Answer
Load Custom Scene 2 Answers