- Home /
Unity sprite packer not reducing draw calls in the UI
Hey,
I've been trying to optimize our game's UI and I wanted to use Unity's built in sprite packer to make a UI atlas.
I can see the atlas being created in the sprite packer window but it has had no effect on the draw calls in the scene. The altas apparently has no effect on sprites used on sprite renderers. It seems like it is still using the separate sprites.
Am I missing something here or is there something generally wrong?
Thanks in advance, Ali
Answer by Matheuz · Oct 17, 2015 at 04:42 PM
About the sprite field on the Sprite Renderer component, Unity abstracts the idea of Atlas and you don't see the renderer sprite's field linked to one (like NGUI used to). It is using the Atlas, but it hides it from you so it's more user friendly.
About the draw calls, overlapping UI elements need a new draw call, even if they are in the same atlas. So if you have a button been rendered in front of a panel and both live in the same atlas, one draw call is necessary for each, since the graphic card can't overlap 2 sprites with one draw call. It first draws the background, then the foreground.
EDIT: My last paragraph is wrong. It is possible to draw 2 UI elements that overlap each other on the same draw call, just like 2 3D objects that share the same material can be drawn on the same draw call even if one overlaps the other. Hence, the problem must be something else.
Thank you for your detailed answer. Creating my own atlas using a 3rd party atlas maker and using that, does actually reduce my draw calls to what I am expecting though.
Interesting, I didn't have any problems with non-overlapping sprites and draw calls. I wonder what's happening. Sometimes using the Frame Debugger helped answering these tricky questions, give it a try.
Answer by hippogames · Mar 30, 2016 at 01:16 PM
When using multiple atlases created by [Sprite Packer] there is strange issue when draw call count is more than atlas count. Maybe it is caused by overlapping. But it doesn't happens when using single atlas even if some sprites are overlapped.
To fix it just assign [Order in Layer] of [Sprite Renderer] according to atlas index. Or just assign incremental index for each separate sprite [1, 2, 3, 4...]. Both methods worked for me.
Your answer
![](https://koobas.hobune.stream/wayback/20220612041642im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity's Sprite Packer or Manually Creating Atlas? 0 Answers
Sprite Alpha Performance 0 Answers
C# making an optimized UI 1 Answer
Sprite Packer also include original sprite in build 0 Answers