2

What's the catch with the UGUI depth sorting by sibling index? I can not see any improvement but only downsides to this

For example, I have a game with a scrollRect that is using several objects. My objects have a few images and some text. If you order them as follows:

-Content

-Object

-Image

-Text

-Image

-Text

-Image

-Text ...etc

You will get 6 drawCalls for each object. For 10 objects that use the same font and the same image, you will have 60 DRAW CALLS!!!

Okay, you can optimize them as follows

-Content

-Object

-Image

-Image

-Image

-Text

-Text

-Text

...etc

And you will have one batch of 3 images and one batch of 3 texts for each object. But you will still get 2 draw calls for each object, thus 20 draw calls for 10 IDENTICAL OBJECTS.

Imagine you have 5 different scroll views with objects inside them (as I do), with 5 objects visible, and each object is a bit more complicated than just an image component and a text components. As a matter of fact, I have the following hierarchy.

-Object

-Text (1 draw call)

-Image

-Image (1 draw call - batched with the one above)

-Text (1 draw call)

-Image (1 draw call)

-Text (1 draw call)

-Image (1 draw call)

-Text (1 draw call)

I can not modify the hierarchy because some images are buttons and in order to keep their texts sharp and centered on every aspect ratio, they need to be children of the buttons and anchored to them. My object generates 7 draw calls, and having 5 visible objects on 5 different scroll views gets me to 7 * 25 = 175 draw calls.

Now, using a z-based depth, we would've had only 2 draw calls. And thus my question arises, what's the catch with this approach? Why would Unity do this? Is there a positive outcome to this and I am too blind to see it?

mironalex
  • 31
  • 3
  • I think this question would be more likely to get a good response on [gamedev.se]. – Nox Nov 20 '15 at 15:10

1 Answers1

0

I guess this all comes back to the rendering order and batching. To investigate what is in individual draw call use Unitys build in Frame Debugger, very useful tool.

If you are looking to optimise this further use Packing Tag in sprite settings. Unity will create UI atlas for you and your draw calls will be drastically reduced.

enter image description here

Greg Lukosek
  • 1,774
  • 20
  • 40