Unity UI draw calls and Grid Layout Group

Hello everybody,

Recently I have been trying to perform some UI optimization for a game. The game includes a list of characters, all organized in a Grid View Layout.

For each available character, I instantiate a prefab and place it on the Grid Layout Group. The prefab contains some UI pieces, but it is basically divided in 4 layers. I made an awful sketch of what I mean (Click here)

The drawing order is cell by cell (as expected by the Grid Layout). But my draw calls count suffer from it.

This means it draws the layers like 1 2 3 4 1 2 3 4 1 2 3 4 …
What I want, is to get the drawing order to be 1 1 … 1 1 2 2 … 2 2 3 3 … 3 3 4 4 … 4 4
That way I could batch each group together in a single draw call.

Is there any known way to achieve this?
I was thinking about using different Grid Layout Groups for each layer, but I am just wondering if there is a better solution.

1 Like

Hi, did you ever manage to fix this issue? I’m encountering the same problem, except my layers go to like 25-30 per cell.

Drawing order being cell by cell is not expected. I made a small test scene according to your sketch, and Unity was able to batch them nicely.

Are any of your elements overlapping with neighbouring cells? That can cause the batching to break, since it can no longer draw the top most layer of each cell first. Also, make sure you are using packing tags for your sprites.