- Home /
Unity3D 4.6.2 Build Crash Out Of Memory
Hello,
I am building a 2D adventure game using Unity. I have a total of 6000 sprites at 1024x1024 resolution, PNG at 32b, and about 42 animations for now, built using Unity Animator. My resources folder is 163 MB.
When I try to build the game on Windows, I get the following crash:
Can't Unity handle that many sprites? Is there another solution for this?
Also a while back, when I had fewer animations and sprites, the built game used about 3.87GB of disk space, while my entire resources folder was around 150MB. How is that possible?
Please let me know if I am missing something or if I should approach this differently. Here is a small video of my game and what I am trying todo: http://youtu.be/6UyJdoCBIrs
Thanks in advance.
6,000 32bit 1024x1024 PNG files is a lot, and it looks like you're simply trying to allocate more memory than (32bit) Unity can access. The only solution may simply be to downsize your memory footprint significantly. What texture compression format are you using for these files?
Why do you mention the resources folder particularly? I'm assu$$anonymous$$g that these are regular texture assets and so are unrelated to the size of the /resources folder, which only contains resources loaded at runtime.
6000 (Thousand) sprites, each 1024 [o_O]. Haven't done anything close to that, but i coud only guess that's too much...
Do you have static batching on?
Why don't you make atlases? (4 sprites combined into 1, etc) this way you will have 1500 sprites? You can still split them in Unity...
Thanks for the answers. $$anonymous$$y images are compressed using DXT5. I don't allocate all those sprites in the same time. Or at least I hope Unity doesn't do that, since I am using the built-in components. I have different animations that I use on one animator.
The game I make is a 2D adventure and I have animations for my main character such as pickup, bend, movement up, down, upper-left, etc.
In the scene I have a GameObject with an animator component that plays different animations, one at a time which are a sequence of around 60 sprites.
I will look into the atlas ideea.
Here I made a small video about the game I am working on so you can make an idea of what I want to do and please let me know if I approach things wrong. http://youtu.be/6UyJdoCBIrs
If each of this sprites is 1024x1024, atlases wont help because you will get huge atlases.
Honestly, 1024x1024 for a body part seems to much to me...
Are you sure you can't reduce the size to 512x512?
AssetBundles could help you build it (divide assets to multiple bundles and build with nothing, load assets in-game)
Answer by smoggach · Feb 19, 2015 at 06:49 PM
Unfortunately if unity wants to pack these sprites or add them to a Resources file it has to load all of them into memory which is impossible in your situation.
The only way you'll get that many to work is to load them individually from StreamingAssets or make asset bundles out of smaller groups of them.
Thanks alot for all the answers. It pointed me in the right direction.
I have reduced the animation framerate so now I have 30 ins$$anonymous$$d of 60 at 12fps. I might reduce this more, if it doesn't impact the quality of the animations. Also I implemented mirror for animation which reduced everything to half. So left its just right but at 180 degrees.
The strea$$anonymous$$g assets or asset bundle seem like a great solution. I haven't worked with that yet, I wonder how I can create an asset to contain just the animation(clip) I need and its respective sprites. Has anyone managed to do this?
I have found how to load clips from an asset bundle here: http://forum.unity3d.com/threads/solved-load-animations-from-asset-bundles.34827/
Answer by Nick110 · Mar 11, 2015 at 09:32 AM
Hello,
To reduce memory what I first changed is that I removed mirror sprites. Now I implemented the "left is right" animations and I flip them from code. This removed like half of the memory usage. But my game was still 1.6 GB.
Next what helped me alot with all the sprites I had is Texture Packer. Not only does it squeeze multiple sprites into one image, but also it can detect similar sprites and include them only once in the image, but keep in sprite sheet the multiple references. That's awesome. Now my game is only 160 MB, it saved me 10 times the memory usage.
I hope someone else finds this useful. I might look into asset bundle solution too later on, and I will be back with information on that one.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
iPhone game turns off unexpectedly 1 Answer
Game Crash When Changing Scene 1 Answer