Search Unity

Sprite Atlas adding on build size.

Discussion in '2D' started by Punfish, Jan 5, 2019.

  1. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    I'm creating a Sprite Atlas for a single texture which has sprites loosely spaced apart. When I generate the Sprite Atlas preview I can see the texture I made an atlas of is packed down densely, creating a much tighter and smaller texture.

    However, when I build the project for Android the APK size increases for every Sprite Atlas. I've verified that Sprite Atlas packs are enabled for engine and builds under Preferences -> Editor. Also, when I untick "Include in build" the textures become empty (white) as expected in Play mode.

    I'm using Anima2D on this project; not sure that could be part of the issue. The textures are not in the resources folder.
     
  2. Sergi_Valls

    Sergi_Valls

    Unity Technologies

    Joined:
    Dec 2, 2016
    Posts:
    212
    Hi @Distul,
    Every SpriteAtlas you create will add to the build size if "include in build" is enabled. Could you clarify the problem you are experiencing?
     
  3. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    I was under the impression the atlas would replace the texture on build thus most likely reducing the build size. Does the original texture also get packed into the build along with the atlas?
     
  4. Sergi_Valls

    Sergi_Valls

    Unity Technologies

    Joined:
    Dec 2, 2016
    Posts:
    212
    Original textures shouldn't get packed into the build, except if you are referencing them from some other asset, like a material. Make sure any asset included in build references your original textures.
    Anima2D had this "original textures into build problem", but that was fixed in version 1.1.4.
     
  5. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    Your latest comment helped me in connecting some dots, and I've managed to find reproducible cause.

    If I use sliced parts of a single texture for both a Sprite Renderer as well Sprite Mesh(anima2D) then the file size increases.
    EG: the texture contains a character as well their weapon, such as a projectile. I use anima2D to animate the character using Sprite Meshes. The projectile however is a separate prefab with a Sprite Renderer.

    Issue can be remedied by making sure Sprite Meshes and Sprite Renderer images don't share the same texture. Have not tested if this holds true for other variations such Image and Sprite Renderer.

    Thanks.
     
  6. Sergi_Valls

    Sergi_Valls

    Unity Technologies

    Joined:
    Dec 2, 2016
    Posts:
    212
    That behavior doesn't look correct. Please could you report a bug? Thanks
     
  7. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    Looking at the Editor.log under
    Build Report
    Uncompressed usage by category (Percentages based on user generated assets only):

    I see my sprite sheet as 44.1 kb 0.0% Assets/Textures/Units/GroundUnits/Extras/Bosses/SwampQueen/Base/SwampQueen_Base.png

    as well the sprite atlas 3.7 kb 0.0% Assets/Textures/Units/GroundUnits/Extras/Bosses/SwampQueen/Base/SwampQueen_Base.spriteatlas

    At one point the sprite atlases worked and the file size dropped about 40%, but out of nowhere they're not and the file size is large again. I've tried Sprite Packer mode Always Enabled and Enabled For Builds. I've tried using Pack Preview on the Sprite Atlas before building as well, just to be thorough. They're using crunch compression, 100% high quality.

    I can try reproducing in a smaller project and uploading as a bug report.

    Maybe worth noting, when the sprite atlases actually worked properly and reduced the file size I saw files with the .spriteatlas extensions being packed into the build beneath the progress bar; when they didn't work properly I do not see them.
     
  8. Sergi_Valls

    Sergi_Valls

    Unity Technologies

    Joined:
    Dec 2, 2016
    Posts:
    212
    Yes, please use Help -> Report a bug feature. Thanks
     
  9. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
  10. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
  11. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    I'm unable to submit a bug report on the project I'm experiencing the issue. I excluded the Library and Builds folder and the upload progressed only 14% in 10 hours. I have 10mbps upload, the submission was taking way longer than it should have.
     
  12. daal

    daal

    Joined:
    Aug 5, 2014
    Posts:
    3
    Hi guys
    I have similar problem
    I've created empty project with one sprite and put it in sprite atlas.
    I don't use that sprite anywhere else except sprite renderer on the scene.

    Build report shows that it includes both and sprite atlas and sprite

    16.1 kb 0.0% Built-in Texture2D: sactx-128x128-ETC2-New Sprite Atlas-8e6d3ac5 ( contains icon_dolar.png )
    0.7 kb 0.0% Assets/icon_dolar.png

    Unity version is 2019.1b. , 2018.3.9f1

    Any ideas?
     
    Last edited: Mar 23, 2019
  13. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Could you please submit a bug-report as described in this document:
    https://unity3d.com/unity/qa/bug-reporting

    It's important that you report these issues together with a reproduction project if you want them to get fixed. If you don't do it, it might be a long time until someone else reports them or until Unity Technologies find them.

    After you submitted the bug-report, you receive a confirmation email with a bug-report Case number. You can post this Case number here (in this forum thread) for Unity staff to pick up, in case they see it.
     
  14. daal

    daal

    Joined:
    Aug 5, 2014
    Posts:
    3
    Done.
    The ticket number is : 1139877
     
    Punfish and Peter77 like this.
  15. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    We seem to be seeing this issue in Unity 2019.2.5. Any insights to why that would be?
     
  16. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    Is this fixed in newer Unity versions? We have this issue in 2019.1.14, but we can't update because it breaks our project.
     
  17. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    @ProtoTerminator @Ben-BearFish
    If a sprite is part of Atlas, the source texture is never added to the build, only the sprite (which does not hold any texture data, just sprite and some geometry info). The only texture that is built for texture is the Atlas texture (sactx-128x128-ETC2-New Sprite Atlas-5788029a)

    Based on above post (https://forum.unity.com/threads/sprite-atlas-adding-on-build-size.608143/#post-4351309) , :
    0.7 kb 0.0% Assets/icon_dolar.png (Sprite) => This is not Texture but Sprite data (vertices, properties etc..)
    0.2 kb 0.0% Assets/New Sprite Atlas.spriteatlas (SpriteAtlas)
    16.1 kb 0.0% Built-in Texture2D: sactx-128x128-ETC2-New Sprite Atlas-5788029a (Texture2D) => Texture for the Sprite.

    Source texture is only included if its also referenced elsewhere other than SpriteRenderer (for example like Material etc..) or inside resource folder.

    The idea of Sprite-Atlas is to pack all source textures of sprites to a single texture and use it as a source for the sprites. So this is exactly as expected.
     
  18. IssacTeoh

    IssacTeoh

    Joined:
    Apr 9, 2014
    Posts:
    4
    After tried many times.:) I finally found out as long as that image/sprite that include in the sprite atlas, not in the Assets/Resources folder then those image wont be include in the build.

    ----------------------------------------------------------------------------
    BEFORE
    Build Report
    Uncompressed usage by category (Percentages based on user generated assets only):
    Textures 14.2 mb 48.1%

    Used Assets and files from the Resources folder, sorted by uncompressed size:
    1005.0 kb 1.5% Assets/Resources/Image/SpotTheDifferentImage/Black Panda.png
    1004.9 kb 1.5% Assets/Resources/Image/SpotTheDifferentImage/Panda.png
    1004.9 kb 1.5% Assets/Resources/Image/SpotTheDifferentImage/PENGUIN.png
    382.4 kb 0.6% Built-in Texture2D: sactx-0-2048x2048-Crunch-SpotTheDifferent Atlas-6a3bf6a2
    171.1 kb 0.3% Built-in Texture2D: sactx-1-2048x1024-Crunch-SpotTheDifferent Atlas-6a3bf6a2
    ----------------------------------------------------------------------------
    AFTER
    Build Report
    Uncompressed usage by category (Percentages based on user generated assets only):
    Textures 553.5 kb 3.4%

    Used Assets and files from the Resources folder, sorted by uncompressed size:
    382.4 kb 0.7% Built-in Texture2D: sactx-0-2048x2048-Crunch-SpotTheDifferent Atlas-6a3bf6a2
    171.1 kb 0.3% Built-in Texture2D: sactx-1-2048x1024-Crunch-SpotTheDifferent Atlas-6a3bf6a2
    6.2 kb 0.0% Assets/Image for Package/Black Panda.png
    6.2 kb 0.0% Assets/Image for Package/Panda.png
    6.2 kb 0.0% Assets/Image for Package/PENGUIN.png
     
  19. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    This is right. By design, anything that you put in Resources folder are always included to the build whether they are part of Atlas or not as the original asset is loadable using the Resources.Load API on the Runtime.
    So if source texture of the Sprites are in Resources folder, both source texture and the atlased texture will be included during build.
     
  20. salihunitydev

    salihunitydev

    Joined:
    Oct 6, 2020
    Posts:
    1
    Hi All I have got a solution as I was getting a size of 2 MB as sprite atlas as I was not using any atlas
    my Editor Log was showing
    2.0 mb 1.2% Built-in Texture2D: SpriteAtlasTexture-New (Group 0)-2048x1024-fmt47

    Atlas was made because some of my sprites were having a packing tag of New which is written after SpriteAtlasTexture
    This Packing Tag can be found right below the Sprite Mode when you change the texture type to sprite 2d and Ui.

    Just null the packing tag and make sure none of your sprites have any packing tag to ensure no sprite atlas made by unity

    upload_2021-5-28_11-47-49.png
     
  21. vuphuonghoang88

    vuphuonghoang88

    Joined:
    Sep 3, 2015
    Posts:
    3
    OMG I spent 2 days scratching my head because of this "duplication" issue.
    Turn out, I ignored its size.
    The "sprite source" assets appearing in the Build Report has much smaller size than the original one. So they're not actual sprite sources, but only sprite data needed along with the real texture packed in the atlas.
    Thank you for clarifying.
     
    stream_in_space_ likes this.
  22. ManuBera

    ManuBera

    Joined:
    Aug 19, 2021
    Posts:
    70
    I'm kind of late to the party, but what if I have a ScriptableObject asset in my Resources folder that holds a reference to a Prefab that contains Sprites that are packed in a SpriteAtlas, will those Sprites automatically be included in the build?
     
  23. metinevren

    metinevren

    Joined:
    May 17, 2014
    Posts:
    30
    Does "some other asset" include Image component? I have a sprite that I use both in SpriteRenderer and UI's Image component. Would this make that sprite to be included in the build separately from the sprite atlas?
     
  24. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    Check if the source texture is set in any Material or other dependent Assets. Also please note that Sprite is an independent Asset that depends on Texture2D Asset. So the build report includes it even if original source Texture is replaced by Atlas.
     
  25. metinevren

    metinevren

    Joined:
    May 17, 2014
    Posts:
    30
    No the source texture is not set in any material. No it is not. In my build it shows that there are spriteatlases, the image files that are supposed to be in the atlases. There are duplicates of those image files with different sizes. And then there are large files that are in unknown category, which I found them to be in Library/AtlasCache folder. I cleaned that folder rebuilt my project but they still appear in the build report. Why are cache files are included in the build?
     

    Attached Files:

  26. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
  27. zudesai

    zudesai

    Joined:
    Sep 26, 2022
    Posts:
    4
    @Venkify
    I am using a scriptable object where I am attaching my sprites.
    I have created a sprite atlas out of these sprites but I am seeing that these files are still included in the build report.
    is it because of scriptable objects which are still linked with individual sprites?
    Is there any way we can use a sprite atlas with scriptable objects?
     
  28. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    Could you please elaborate ? Or post a simple repro so we can help you better ?
    The original paths will still be reported in the Build report as Sprites and Textures are different assets.
    Sprites belong to the original PNG and they will still be reported.
    Texture2D that originally were imported in PNG will be replaced by Sprite-Atlas textures.
     
  29. zudesai

    zudesai

    Joined:
    Sep 26, 2022
    Posts:
    4
    I have theme implementation in my game. This implementation is using scriptable object of each theme where we attach theme-specific sprites. At runtime, we use this scriptable object to get the correct theme sprite and update the UI.

    Now, I want these individual sprites to be packed in a sprite atlas. This will help us in reducing our app size.
    Atlas creation is simple but I am struggling to figure out how can I give this atlas to my scriptable object which has all the individual sprite fields.

    Here is my current implementation. I want to use sprite atlas instead of this individual sprites.
    Unity_SpriteAtlas.jpg
     
  30. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Currently at latest Unity 2022.3.22f1 LTS, the sprite atlas is still completely unusable that sprite atlas force to set Compression to None to fix bad sprite quality issue which make the game build size extremely high which totally unacceptable. Officially really need to fix it asap since the issue is still at there way too long time.

    upload_2024-3-29_10-56-51.png
     
  31. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    The texture format of only the source sprites (png, psd etc..) should be set to uncompressed. The format of the SpriteAtlas can be set to any format you prefer (compressed/uncompressed). You can do so in the Inspector
    Unity - Manual: Sprite Atlas V2 (unity3d.com)