I have two sprites (they look the same but with different colors):

enter image description here

I want them to be positioned like on the image above, so there's a feel like blue is standing on the green one. There are two ways to achieve that:

  • Blue block with Order in layer 1, Green block with Order in layer 0
  • Blue block with lower Z coordinate, so it's physically in front of the green one.

Both of the concepts appear to break batching between these two objects. They're on the same atlas (I've tested it by setting the same Z position and Sorting Order and batching works).

How can I achieve batching here?


No, order (be it due to different Z position, different Order in layer, etc.) doesn't break sprite batching.

The most probable cause is that those sprites are using different Materials: you can't batch such sprites.

| improve this answer | |
  • 1
    \$\begingroup\$ You can, however, achieve different colors with a single material by using a MaterialPropertyBlock \$\endgroup\$ – Draco18s no longer trusts SE May 18 '18 at 22:30
  • \$\begingroup\$ @Draco18s Do you think that the MaterialPropertyBlock could be useful for sprites' colors? What I mean is that I understand the use of it for 3D, mesh rendered objects, but in the case of the Sprite Renderer component we already have the Color property. \$\endgroup\$ – Galandil May 18 '18 at 22:36
  • \$\begingroup\$ SpriteRenderer inherits from Renderer, which is what supplies SetPropertyBlock, so I assume it works. \$\endgroup\$ – Draco18s no longer trusts SE May 18 '18 at 22:40
  • \$\begingroup\$ No, I don't mean that, functionally they both work the same, but when dealing with sprites I found that using the Color property is better since we can change/see it directly in the Inspector on a sprite-by-sprite basis without having to look at code. \$\endgroup\$ – Galandil May 18 '18 at 22:42
  • \$\begingroup\$ Point. I don't know if that breaks batching or not though, the documentation doesn't say. \$\endgroup\$ – Draco18s no longer trusts SE May 18 '18 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.