Sorting layers: what the philosophy of it ?

Hello!

In short I don’t understand how to use sorting in 2D.
In long:
Let’s say you have a tree object, which structure is this:

  • root
    |-branch1
    |-branch2
    |-branch3

branch1, branch2 and branch3 are chilrdren of root and are Sprites(have SpriteRenderer component)

So to place one brach over/below the other you could do one of these things:

  • Change z-coordinate(I thought it should work, but it doesn’t).
  • Change orderInLayer.

Changing orderInLayer works, however… this parameter is global within the layer. If you place 2 trees and, say, one tree is below(by y-coordinate) the other, the tree that is at the top should be drawn first. But how could I do that using sorting layers ? I suppose there is no answer on this question so I ask the other one: How to sort objects(complex objects with children) in Unity 2D ?

Thank you in advance.

You can use Sorting Groups to sort groups in front of each other:

https://docs.unity3d.com/Manual/SortingGroup.html

1 Like

Wow… I didn’t know about such component. Thank you very much!