Search Unity

UI system with sprite atlases

Discussion in 'UGUI & TextMesh Pro' started by Shadarath1, Jan 28, 2019.

  1. Shadarath1

    Shadarath1

    Joined:
    Jan 24, 2015
    Posts:
    6
    Hi,

    Could someone help me understand how to get Unity's magic automatic atlas building to cooperate with UI system?

    I made a simple test scene that renders two images on a canvas. The problem is that for some reason it is drawn with 2 batches. I think the problem is with how Unity builds sprite atlases, because if I manually pack those two sprites to one texture (with sprite mode "multiple") It is properly rendered with only 1 batch.

    Let me present this setup on a screenshot for improved clarity:


    Bad batching:




    Good batching:




    Only thing changed between those two is Source Image property on both Images.

    Could someone explain how to get automatic atlas building to work?
    I tried it both with and without 'packing tag' set, makes no diffence.
    Do I have to manually pack all sprites if I want to avoid riddiculus amount of batches in rendering?

    Thank you for help
     
    Shorely likes this.
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Whats the packing tag on GearA and GearB? My guess is there is no tag so its not packed.
     
  3. Shadarath1

    Shadarath1

    Joined:
    Jan 24, 2015
    Posts:
    6
    Packing tag is set to the same value for both sprites, as I mentioned in the post it makes no difference


    Edit:
    If it matters my Unity version is 2018.3.0f2
    Here are my import settings for both sprites:
     
    Last edited: Jan 29, 2019
    Shorely likes this.
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Then i would double check that the project settings for using the sprite packer has not been disabled. It has 3 modes Disabled, Enabled for Builds (packing is used for builds but not Play mode) or Always Enabled. I say that as what you've done on the sprite level is correct.

    Edit > Project Settings > Editor.
     
  5. Shadarath1

    Shadarath1

    Joined:
    Jan 24, 2015
    Posts:
    6
    Unfortunately not, I had it set to Always Enabled. I also tried with Legacy Packer setting but it still does not work..
     
  6. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Hmm, could you file a bug report with your sample project and then give me a bug number its got to be something simple but dont know off hand.
     
  7. Shadarath1

    Shadarath1

    Joined:
    Jan 24, 2015
    Posts:
    6
    Last edited: Jan 30, 2019
  8. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    So you seem to be right, the Sprite Atlas asset is the new way forward. In the project settings there is a packing mode for "Always Enable (legacy)" which works when using the packing by name such as you have done.

    Edit: So yes this is the new behavior. Any new project created will default to "Always Enable" in which case the packing tag is ignored as it uses the new Atlas system.
     
    Last edited: Jan 30, 2019
  9. Shadarath1

    Shadarath1

    Joined:
    Jan 24, 2015
    Posts:
    6
    Ok, thank you very much for clarifying!
     
  10. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    two options

    1) use the package tags thats on the sprite asset importer AND set the Edit > Project Settings > Editor packing mode to Always Enable LEGACY

    2) use the sprite atlas asset to define what packaged AND set the Edit > Project Settings > Editor packing mode to Always Enable.

    Shadarath1 was saying that #1 wasn't working for him though my testing showed that it did with his example he gave me so either or should be ok. #2 is apparently the preferred way according to the 2D team.
     
    tobetobe likes this.