Search Unity

Big problem with Sorting Group component

Discussion in '2D' started by b4gieta, Aug 4, 2019.

  1. b4gieta

    b4gieta

    Joined:
    Jul 17, 2018
    Posts:
    97
    Hi
    I have a body made of sprites. They're all set to the same Sorting Layer and Order in Layer (first is "People" and the second is 0). The trick is all parts of body are on different Z positions. But when I add Sorting Group with the same settings ("People", 0) to the parent of them all, it gets... broken? Everything is in screens. I don't know why it happens. Any ideas? I'm using orthographic camera.
     

    Attached Files:

  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    This is because SortingGroup is a 2D component and it uses hierarchy order as a fallback sorting instead of depth.
     
  3. Sam_Ooi

    Sam_Ooi

    Unity Technologies

    Joined:
    Mar 5, 2018
    Posts:
    61
    Hi!
    When you parent the different Sprites to the parent GameObject with the Sorting Group component, their individual Distance to Camera (Z position) are ignored during the internal sorting process within the Sorting Group; all their Z positions become the same as the Z position of the parent with the Sorting Group component.

    Since you gave them all the same Sorting Layer and Order in Layer values, they are sorted together on the 'same' layer and their render order became jumbled. Ideally, you should give each of the Sprites a different Order in Layer value so that they are sorted in the correct Render order, while remaining on the same "People" Sorting Layer.