Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by john-essy · Sep 11, 2017 at 11:42 AM · unity 5uimemorymemory managementmemory usage

Unity Sprite Memory Usage Is Huge

Hi there,

Can anyone let me know how to reduce the memory size properly for my sprites on my UI. As right now it accounts for 227.8MB of ram usage in my game and the total Ram usage is only 340.05MB so the sprites are taking up a huge amount of space. It is that bad, that when we load our next scene async it crashes on apple devices.

What is the correct process of doing this, Our UI Designer doesn't want to make all the UI Power Of 2, Should he or is there another solution to this?

We are developing for IOS & Android

alt text

screen-shot-2017-09-11-at-123915.png (177.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by IgorAherne · Jan 12, 2019 at 09:34 PM

1) you really got to use power of 2, or at least pack non-power-of-2 sprites into power-of-2 atlases. This allows to use nice compression for your sprites. All sprites must be compressed as much as possible. Use RGB instead of RGBA where possible. Ensure there are no mipmaps (if this is acceptable) - this will reduce size by extra 33%


2) Create a manager singleton, that loads the sprite from Resources, and provides it to anyone who requested. Instead of using references to sprites, query the manager when needed.


3) Make that loading asyncronous. In other words, let the manager output a sprite through a callback, not immediatelly.


4) Make the mechanism that allows the manager to reclaim the Sprite, telling the users to stop referencing it (perhaps, when your custom memory-limit is reached). Afterwards, the manager can destroy and unload the reclaimed sprite from memory. This can be done via the following:


 public class ManagedSprite{
      public Sprite sprite;
      public System.Action _onStopReferencingSprite;
 }
 
 class Manager{
      
     public void RequestSprite(System.Action<ManagedSprite> OnSpriteLoaded){  
             //...load sprite async, maybe via some coroutine...
             //invoke OnSpriteLoaded once done.
     }
    
     void internal_ReclaimSprite(ManagedSprite ms){
           ms._onStopReferencingSprite?.Invoke();//tell everyone to stop referencing our sprite
           Destroy(ms.sprite);
           ms.sprite = null; //<-- stop referencing, so it can be Garbage Collected.
           ms._onStopReferencingSprite = null;
           Resources.UnloadUnusedAssets();
     }
 }//end Manager
 
 
 class SomeUser{
      [SerializeField]  Image myImg; 

      void foo(){
            Manager.instance.RequestSprite(  OnSpriteRdy  );
      }
 
      //called several frames after, when the sprite is finally loaded
      void OnSpriteRdy( ManagedSprite ms){
             ms._onStopReferencingSprite += OnStopReferencingSprite;
             _img.sprite = ms.sprite;  //use the actual sprite, as needed.
      }

      //called for us when the Manager wants to take away the sprite from us.
      void OnStopReferencingSprite(){
             _sprite = null;  //<-- stop referencing the previously provided sprite, so it can be Garbage Collected after destroy.
            _img.sprite = null;//ensure image forgets about it too.
      }
 
 }








Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

175 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WEBGL Memory Usage Problem 1 Answer

Why is the memory used of a level going up when entering the level from another level? 1 Answer

Unity Image Loading System optimization request 1 Answer

Is this memory usage too much for a mobile game? 1 Answer

FATAL EXCEPTION: UnityMain on some Android devices 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges