My app just came out yesterday, feedback says it works well on the 3GS but it crashes miserably on the 3G. Problem is with the memory usage. I’m using the resource.load to load certain assets and that particular button is pressed. Thought it might have fixed it but still having problems.
What I would like to know is for those who are experienced in memory optimisation, particularly when using SpriteManager 2, how do you optimise your code amd what are the best techniques?
My app is around 104 megs-ish. How I call resource.load:
spriteIIdle01a.renderer.material.mainTexture = Resources.Load("char_idle01a");
// I have loads more of something like this on certain buttons.
Do you use Resources.UnloadUnusedAssets and manual GC techniques to keep your memory low? Are you creating too much variable data in you game classes? Do you take advantage of PRVTC compression on your Textures?
Is your app 104 megs in data size or 104 megs in Real RAM on the device? Using tools like instruments are vital, it will help you figure out when your ram is going up and by how much. You may need to scale back your program if you are using very RAM intensive stuff like audio and uncompressed textures.
Also remember that using Resources.Load can actually hurt you. Objects in Resources are always included in your build, so keep this in mind if you have assets that don’t get used very often, or at all.
I did read about Resources.UnloadUnusedAssets but I thought it’s unavailable for Unity iPhone? I’ll check again later. To make my app work on iPhone 3G and anything with 128 Megs, I had to use PVRTC.
What did you mean tools like instruments? Is it something the can be integrated with Unity? My app is 140 Megs in size, can’t tell how much RAM I’m using. Even with the Stats switched on in Unity, the RAM didn’t look like it was too much, aroung 5-6 megs.
The things about my app is that every asset will always be in used. Once I destroy it’s a bit hard to instantiate it again. Not sure if I can keep instantiate and destroy over and over again. I’m not sure how to describe it, but the app is an interactive character where you can swipe or press some buttons to make him do stuff.
Thanks again for the advice, I think I need to get back into basics and learn to optimise things properly. Even codewise, mine is just full of if statements
Well we have a fighting game that plays fine on 3G devices and has 79 animations, customizable textures and model parts. So it can be done, we have been able to squeeze out some amazingly detailed model geometry by reducing programming overhead.
You will need to use all of the resources available via forum search to get all the tips and tricks. However the only way to quantify your results is by patiently running debugging tools provided in xcode. Be sure to use the unity profiler in your appController.mm and instruments in XCode to figure out what scenes and even what function calls are intensive in resources.