Search Unity

Unity UI Should we still use Sprite Atlas for performance?

Discussion in 'UGUI & TextMesh Pro' started by mmalavasi, Jul 31, 2018.

  1. mmalavasi

    mmalavasi

    Joined:
    Jun 21, 2017
    Posts:
    13
    Hi, I'm using Unity 2018.1.3f1 and I heard that with the new UI we don't need to use atlas anymore in order to reduce drawcalls in canvases because Unity is (magically) creating its own atlases for sprites internally. So I was wondering, is this really true or should I create Sprite Atlas for my UI like the old days?
    Also, after creating a sprite atlas, could that work also with the Image component or just with Sprite Renderer?
    Thanks!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
  3. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    that doesn't look as if unity is doing it magically in the background. It is still a tool you have to use.
    If the tool didn't change a lot since I tried it the last time, I would buy TexturePacker instead.
     
  4. mmalavasi

    mmalavasi

    Joined:
    Jun 21, 2017
    Posts:
    13
    I assumed from karl_jones answer that his "yes" stood for "you have to make your own atlas for your UI using the SpritePacker" and not "the SpritePacker automagically generates Atlas internally and you don't have to do anything", but now that you mention it I'm not so sure and I could be wrong :D
    I run some tests with the Frame Debugger, just look for the draw calls for some images on a canvas before and after creating an atlas, and it seems that creating an Atlas actually reduces the number of draw calls to 1 and instead you have one separate draw call for every image when there is no atlas. So it seems that Unity UI is not doing any kind of magic by itself. The only thing that it does it's batching the same sprite if you repeat it more than once, even if it's not into an atlas, so that you have one draw call for it.
     
    Hosnkobf likes this.
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    It is packed internally magically. You use the Sprites as individual sprites and don't worry about the atlas. Unity generates the atlases when building the game or playing in the editor(configured in settings).
    You need to provide a packing-tag to each sprite, this tells Unity how to pack/group them. The sprite packer window lets you preview the atlas textures and also make adjustments(change how tight they are packaged etc).

    This is a pretty good description:
    https://forum.unity.com/threads/why...ready-using-packing-tag-in-my-2d-game.386503/
     
    Novack likes this.
  6. mmalavasi

    mmalavasi

    Joined:
    Jun 21, 2017
    Posts:
    13
    Uhm...the thing is that when I try to access the Sprite Packer it says it's a legacy component and I need to enabled it from the Edit settings. Why do I need a legacy component? What I did is going to Edit->ProjectSettings->Editor and there selecting under Sprite Packer, Mode, "Always Enabled" (so not the legacy one). Then I was able to create a Sprite Atlas where I've assigned all the sprites... but from what I understand this is not the correct process and I have to use the legacy SpritePacker and the old tag system... I'm a bit confused T_T
     
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Sorry yes, you are right. Sprite packager is legacy. Instead, you create a Sprite Atlas asset and assign the sprites to this.

    https://docs.unity3d.com/Manual/SpriteAtlas.html

    Other than that it's the same. You just use the sprite like you would normally.
     
    Novack likes this.
  8. SmartMediaNL

    SmartMediaNL

    Joined:
    Sep 29, 2016
    Posts:
    77
    Well so far as i understand its not the same. You can't use tags anymore but you need to add the sprites you want included to the list. Wish is fine by me by the way this way you can monitor when the sprites do not match anymore in the atlas and rather then let Atlas make a second image for you best thing is creating a different atlas and move the sprites around between the 2 so to optimize the draw calls.
    If you add the same sprite to different atlas objects then a random atlas is used. You can change this by picking the sprite atlas you want to use by script of that sprite gameobject.
     
  9. CuriousPatient

    CuriousPatient

    Joined:
    Aug 12, 2014
    Posts:
    9
    Any exhaustive resource that fully describes the differences between Sprite Atlas workflow and Sprite Packer one? What about 3rd party external solutions? Any objective comparisons?
     
    ecv80 and Novack like this.
  10. Milo_del_mal

    Milo_del_mal

    Joined:
    Jan 27, 2013
    Posts:
    43
    I have always used TexturePacker Pro, great resouce, plugs and play, does not interfere with normal unity flow.

    But in the project I am at right now, they use sprite packer; I understand tha the diference is that on the atlas, you have more control on what goes on which atlas, unlike the packer which just randomly puts together sprites of the same tag
     
  11. sbijur

    sbijur

    Joined:
    Sep 16, 2019
    Posts:
    1
    Does Sprite Atlas support the old sprite sheet created using texture packing method?