Sorry to ask this question, but after reading the documentations, I still can’t understand how exactly do you use Resources.Load? And when to use it and why? For this question, I’m using JavaScript.
I’m making an iPhone App and if it has uncompressed textures, the app will crash. I was told that it’s because there’s a lot of assets loaded at the start of the app. Basically I need help on memory management. So I was advised to use Resources.Load.
For now I have created a “Resource” folder in the project View. Should I copy my assets there or the prefabs only? When I load something from a resource folder, should I unload it after used? I remember something like a constructor and destructor in C++ but not sure how it works in Unity. Also, in code e.g. Animations, the sprites are referenced in each state so if I unload something that’s referenced, wouldn’t that crash the app as well?
Hope someone can explain about memory management and using Resources.Load especially in unity iPhone.
First of all, Resources.Load is the place to load any kind of assets at run time. Like, you can place sound, texture, prefab etc and access the use it on demand.
This will load a texture which is placed in Resources/Images/Track01 directory in the project hierarchy and the texture name is “grass”. Remember it’s loading not instantiating another copy of it. So, it’s not your responsibility to call Destroy() function. What you can do is,
set null to the assigned game object or placeholder.
The call System.GC Application.Unused…
If you create the Instance of it, then it’s your responsibility to call Destroy it.
There are many way to reduce the memory load. Some of them are in short description:
[For Mesh]
Remove all texture default reference from Material.
Load texture at run time from resources directory and assigned it the material properly.
Set null to material texture before leaving the current scene.
You can do this for UI texture as well but need to very careful and manageable in code. Always try to use pixelInsect instead of transform to place GUITexture in the UI.
Use dummy loader in between scene loading. You will get lot of help in this forum. Just find by some proper keyword
All of these technique helped us to keep memory in minimal range like max 40 MB at game http://drift-mania.com/