Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Huge Ram memory for spritesheets?!

Discussion in 'Scripting' started by mahdiii, Jun 23, 2018.

  1. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    Hi all. When I use memory profiler section and detail tab, I see my spritesheets take huge RAM memory!
    some of them take 46mb and most of them take 26mb of ram?!
    My spritesheets are 2048*2048 bilinear and normal quality without mipmap. My platform is android.
    and another question, if I use mip maps for textures, they need more RAM?
    In the inspector,
    I see 4 5 mb for textures
     
    Last edited: Mar 26, 2020
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    Well yes, of course mipmap'd textures will take up more space since a mipmap store precalculated lower resolution texture copies. A mipmap is a way of using more memory to speed up draw calls by using lower resolution versions of a texture in places where the lower resolution version makes sense (distant object for example).

    As for the size.

    On disk an image will be smaller since it's compressed. In memory it'll take up its uncompressed size.

    The uncompressed size depends on the formatting of the image (and mipmaps of course). But consider if you have a 4 channel RGBA image with 8-bit depth per channel. That's 4 bytes per pixel.

    4 * 2048 * 2048 = 16,777,216

    That's about 16 megs right there. Other data can then pad that out further.
     
    mahdiii likes this.
  3. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    Thank you, so why are they 40 and 26mb?
    How can I reduce it? with 16bits depth textures
    Can I compress them in RAM and when I need to render them, uncompress them?
    Do I have to use Resources.Load and UnLoad?
    so if I have only 10 spritesheets, it takes up 260mb, it is so huge!
    In the profiler , it says, it takes up almost 600-700mb of RAM only for textures but when I see maximum usage of this app in my android device, it has written 400-500 mb
     
    Last edited: Jun 23, 2018
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,091
    Check the compression settings in the texture import settings for the images that are being used as sprite sheets. Below is the manual entry for the different compression settings and the platforms that support them. You might be able to reduce them further.

    https://docs.unity3d.com/Manual/class-TextureImporterOverride.html
     
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    Question... are you running this debugger in the editor or on the build?

    Because when you're in the editor it's going to show the total memory used by all textures, and in editor mode this will include any and every texture loaded including those used by the editor.

    For example, in a simple project I have a loaded up a scene with a single quad with a single 2048x2048 texture on it. And it shows this in the profiler:
    memory_usage.png

    But note, that's for 2090 textures. Not just the single texture.

    Yet, when I build and profile that I get this...
    With mipmaps:
    memory_usage2.png
    Without mipmaps:
    memory_usage3.png

    That's using just standard default compression settings from Unity.

    ...

    And for full clarity, here it is with uncompressed texture:
    memory_usage4.png
     
    Last edited: Jun 23, 2018
    mahdiii and Ryiah like this.
  6. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    I use the detail section. See figure below.
    If I use RGBA 16bit, it takes up 16mb for 2048*2048 spritesheet.
    If I use RGBA 32bit, it takes up 32mb for 2048*2048 spritesheet.
    If I use RGBA compressed ETC2 8 bits, it takes up 20mb for 2048*2048 spritesheet.(It uses 8 bits per pixel but 20mb instead of 4mb!)
    If I use RGBA crunched ETC2, it takes up 8mb for 2048*2048 spritesheet.

    default setting for android is RGBA compressed ETC2 8 bits?
    I can not find RGBA compressed 4bits.
    If an android device does not support ETC2, what compression does it use?
    I can change compression format and depth in quality setting?
     

    Attached Files:

    • sss.png
      sss.png
      File size:
      111 KB
      Views:
      787
    Last edited: Jun 23, 2018
  7. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    Screenshot?
     
  8. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    Here thank you. It is in editor
     

    Attached Files:

    • fig.png
      fig.png
      File size:
      500.8 KB
      Views:
      729
  9. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    In sss.png it takes up 16 megs, which is what is expected from an uncompressed 2048x2048 image. I don't know the context of this image so I can't really say what's what.

    As for fig.png, it's still in editor mode. When in editor mode the profiler often reports extra stuff. For example when I ran an uncompressed texture in editor mode vs build mode. I got 16 megs in build, but 28 megs in editor. Not sure exactly why, unity probably still mips the image or other stuff for editor purposes.

    My main take away is... don't trust what the editor says memory usage is if you're looking to test memory usage for a certain device. Instead build for that device, deploy to that device, and then connect the profiler to that device (if it was built in development mode it should show up in the little profiler dropdown that says 'editor>'... if not, you can manually type in the IP).

    I'm outs though, time to get married. Weeeeeeeeeee.
     
  10. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    853
    Yes I tested it in runtime on android device. It takes up 4mb. Thanks
     
    Last edited: Jun 24, 2018
  11. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,731
    Congratulations :)