- Home /
Resources.Load too much on Android = crash.
I resources.load about 500 objects at the beginning of my game. Each is about 8kb, and each comes with an image about 200kb. Profiling, the total amounts to about 100mb ram usage, my entire game about 200mb total ram usage.
My android phone has 1GB ram, nothing else running to hog memory. The game works fine if I Resources.Load a smaller number of objects (tested with 50), but if I try to load all of them at start the build crashes after launch. It loads all of them fine on PC, just not on Android.
Is there some sort of secret ram usage limit I don't know about?
I know I could just not load all resources at once, loading and unloading as needed, but I intended to use all objects simultaneously in game (eventually). I just need to know if this should be possible before I start investing time in alternatives. If so, why isn't it working? And how do I fix it from crashing?
EDIT: I'm not even resource.loading the images, only the prefabs that reference them, so I doubt they're the issue. I compressed them recently to be sure, from ~200kb each to ~50kb each. Didn't make a difference. Next I could test loading the objects without any components at all, and see if it's a component or just loading the gameobjects (already pretty sure it's the latter).
There's something about Resources.loading 500 (lightweight objects) on mobile that causes the app to minimize on Android devices while loading. Tabbing back to the app just loads and minimizes again. The unity profiler says the game uses ~200mb of ram, barely any rendering, and like not even 2% cpu usage. Everything else is nothing. Which makes sense.
Idk if this is a performance issue or not, it only happens when I load a lot of these objects, but the end performance hit is still so small idk why it would crash from it. The only performance hit that isn't super light is ram usage, but 200mb on a 1GB phone, idk what the problem is.. I'm so confused. :(
What kind of objects are they? If they're mostly all from the same prefab, pooling might be a better option.
They're 500 unique prefabs. I'm not instantiating them, just loading them with resources.load. Each is 8kb, and each has a different png image about 50kb each (compressed them recently).
Geeeeez..... That's a lot of prefabs :O
And loading them normally as you need them is too slow?
Also, did you put the PNG files in an atlas? Assu$$anonymous$$g you're using them as sprites?
All 500 objects are eventually going to have different properties, they're not all the same object. For now they're all just sprites for testing purposes.
Well, then I can't really help you mate. Sorry. Try putting the sprites in an atlas and see if that helps. Otherwise I would just load the objects as they're needed.
Your answer
Follow this Question
Related Questions
Lot of resource files 1 Answer
ridiculous load time using Resources.Load() on android build 0 Answers
unity android dll seg fault signal 11 0 Answers
create an AndroidJavaObject within a Thread 1 Answer
Android thread causes crash? 1 Answer