Search Unity

2D single graphics file size

Discussion in 'General Graphics' started by Johannski, Feb 5, 2015.

  1. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Hey there,

    I'm developing a game for mobile devices, and noticed, that my effort for small graphics somehow was ignored by Unity. I have a lot of simple graphics, that are more or less just masks. The png format can work with them very well, but the imported size of them, is just off the hook. Does anyone know, how I can fix this.
    Here is an example:


    5,43 KB is the actual size, and Unity somehow blows it up to 128 KB.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unity does not use source files for anything after you import them; there are no png or jpg files in a build since graphics cards do not use those formats. The only thing that matters is the import settings in Unity. You can change the format to compressed (which you seem to have done, but not for the platform you have active since it still says 16 bit, or else you don't have compress assets on import checked in the preferences).

    --Eric
     
    theANMATOR2b likes this.
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Hi Eric, thanks for the answer. I do have compression at importing enabled, and also didn't override the settings compression for other platforms (I'm developing for Android).
    So why isn't compressing further? Has the compression problems with alpha channels? Also a just blank white graphic, with a resolution with 256x256 has a ridiculous file size of 32 KB (The png for that has 645 Bytes!)... can't I do anything about that?
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    if you would not us it for the UI i would recommend to set the texture type to advanced and set the format to Alpha 8.
    Sadly the UI seems not to support it. Maybe you can go the way over a rawimage component with a Alpha 8 texture.

    For the compression: The format that Unity can support are compression formats that the GPU can use. png is a CPU compressed format and the cpu can take much more time if it like to open an png.
    If you open a png in an image viewer and it would take for exampe 1 second, thats not fast but its ok.
    If the GPU wold need 1 second to decode the png, you would have a 30 - 60 frames drop because the GPU is waiting for the texture.
    The GPU does not have so much time to decompress the image so it does not support formats that compress images that good like png.

    Overall , how many gui textures do you have?
    I had a very complex gui with a lot of icons and special icons and i got it all on a 1024x1024 sprite sheet (with NGUI but the sprite sheet in unity should be able to do the same.)
     
    Johannski likes this.
  5. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Thanks for your extensive answer! I can actually use both of your tips really well, I also got graphics that are really simple, but aren't used as UI graphics. I also didn't think of putting them in one file, which totally makes sense!

    As for your explanation with CPU and GPU: I thought, that maybe Unity is able to keep the png format, and change it to a GPU supported format, once the game is running. That way, the file size of the app would be way smaller, but I guess it would take too much processing power to convert all graphic files at runtime.

    Thanks again, now I got an idea, of how to optimize my graphics!
     
    theANMATOR2b likes this.