How can I display big animation without IOS crash?

I have a problem with running animations on IOS - Unity loads up all the sprites linked to script before the scene even starts (no matter if its animation controller, animation or just script with sprites). When it loads all the sprites the IOS crashes cuz of memory - the app is supposed to work on Ipad mini which have 512mb ram (though IOS terminates app when it uses up >=50% of memory). So now - how can I resolve this problem? So for example: How could I run animation with:

  • 1024x1024 sprites
  • no compression
  • 30fps
  • 60 sprites in total

without IOS crashing? Loading sprites from HDD is too slow…

The only way you’re going to accomplish this is by using PVR sprites which look absolutely terrible or you’ll have to stream your raw images in and out of memory or load the whole thing asynchronously and unload it immediately after it’s done (if it will even fit)

I found that I could not stream 1024x768 sprites fast enough with unity code. I managed to get my loading code fast enough to run most animations at 12 fps on any iOS device. I know that natively you can accomplish what you want though. You’ll probably have to stream your images in and out of memory with native code. The code i used to load my frames was a WWW file:// request for an image in the StreamingAssets folder. I’d then create a sprite out of the www.textureNonReadable.

Here are a few gotchas that I encountered while building my raw image animation system:

  1. Sprite packer tries to decompress and load every single image at the same time. If the amount of memory it takes up exceeds the amount your operating system can handle unity will crash. I think this may have been recently fixed though.

  2. The same goes for Resources except it’s sneakier. If the raw uncompressed size of all your images in memory exceeds your system’s limit Unity will build a corrupt Resources.assets file. I reached this limit with 10000 images or so.

  3. Load as much from the disk as you can. Why? Because you can do this asynchronously. Unity’s LoadLevelAdditiveAsynch isn’t actually asynchronous (the system still chugs). You can also unload it when you’re done and have more control over whether it’s in memory or not. However you end up with slightly longer loading time. My strategy was to treat all the static images in my scenes like normal sprites and include them in the scenes and load everything else from disk as required. This is also useful for supporting multiple resolutions.

It would be nice if Unity included a feature for us folk who need to stream images from disk and don’t believe in PVR.