- Home /
Sprites and minmizing memory usage
What is the best way to handle sprite memory usage in terms of just loading sprites on demand and unloading them, etc?
I have a scene that contains a lot of UGUI components with image renderers. At certain points I deactivate gameobjects, does Unity unload sprites attached to those gameObjects? Is there an easy way to achieve this loading/unloading mechanism?
Answer by Naphier · May 13, 2016 at 05:56 PM
If the objects are in the scene, but inactive the images and everything are still in memory. However, they are not being rendered so there's no cost related to CPU/GPU for them. Best way to truly understand what sort of impact your setup has is to start looking at the profiler window. Then you have to make the decision: Is it better to load a prefab of the UI and destroy when done with it OR leave it in and deactivate it.
Is destroying the object the only option? Since these are GameObjects that are to remain in the scene (and have internal states I want to preserve) but be activated/deactivated at various points, I'd rather have a solution that unloads/loads the sprites only.
You might be able to set the SpriteRenderer's sprite to null then let the GC take care of it. What's your profiler saying for memory usage? Beware of optimization without need.
Your answer
Follow this Question
Related Questions
NGUI Texture front of Sprite 0 Answers
How Can I Reduce Texture Memory Of Background? 1 Answer
How can I access a sprites texture and add it to a GUI button? 0 Answers
Gui.Box - Sprite 0 Answers
SpriteAtlas clone memory problem 0 Answers