SpriteRenderer Draw Calls and Sort Order

Hi,
I have the following problem, our characters are build from a base skin and small clothes parts over it. Currently for one character, we have two atlases, one containing the skin and other containing clothes/face/hair and etc.

The problem is that currently for one character we have around 15 draw calls, instead of just 2 draw calls. All sprites are on the same layer, but with different Sort order. Some sprites from the clothes atlas are under the skin, some are over the skin. If I pack the skin and the clothes into one Atlas, the draw call number is dropping significantly.

Is this normal behaviour or is this some kind of a bug?

Here is a screenshot of what I mean:

The white images are in one atlas and the black in another, drawing this sprites, no matter if they are moved along the Z, or they are sorted using Sort Order, takes 4 draw calls. I guess it make sense, but most people would think that, if the images are from two atlases, the draw calls will be 2.

While I haven’t looked at the innards of Unity, usually, when you’re writing a sprite engine, you bind a texture, draw a bunch of geometry that uses texture, and then bind another texture, and draw more geometry, etc. Each of those texture swaps represents a draw call.

The trouble is, when you are using an explicit draw order, it has to process your sprite quads sequentially, so they appear in the right order. It can only batch up until it encounters a quad that uses a different texture. At that point, it has to bind a new texture.

If it tried to draw your above example in two draw calls, your sprites would appear in the wrong order.

This is why it’s (obviously) best to fit as much into one texture atlas as you can.

One approach you could use would be to composite your customization elements (your clothing) into the base atlas at runtime. The downside to this would be that every customizable character on-screen would require a unique composited texture.

Or just live with it? 4 draw calls are not much to worry about, depending on the rest of your graphics, of course.