Search Unity

Official [Discussion] An option to ignore parent Sorting Groups

Discussion in '2D' started by rustum, Sep 29, 2021.

Thread Status:
Not open for further replies.
  1. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    An option to ignore parent Sorting Groups
    ⚠️ Important Note: The functionality described here is not available and is not confirmed to be released.

    Greetings 2D folks! We are considering an improvement to 2D sorting and would like to hear your thoughts.

    The Problem
    It is often desirable to decouple a renderer’s draw order from its place in the scene hierarchy. The primary use-case we are exploring happens when renderers in a Sorting Group have a child renderer that needs to override that group’s sorting order. The objects can still be connected by a parent/child relationship when it comes to transformation, but can be sorted and rendered without that constraint.

    Our Proposed Solution
    We are exploring an Ignore Parent Sorting Group option on the Sorting Group component. When this is active it will make the Sorting Group sort with renderers at the root level of the scene.

    Here’s an example of the option in action:
    Ignore Parent Sorting Group.png

    The character (in a Sorting Group) has a child sprite (the blue light rays) that should always sort above everything. The Glow child object on the character on the right (Knight B) has this option applied, while the character on the left does not. Notice how the Glow Sprite Renderer can now override its parent's Sorting Group and sort relative to the root level renderers. In this case we have chosen to make it render above the Crate Sprite Renderer.

    Let’s discuss!
    • How well does this solution fit your goals and objectives?
    • In what situations would it work well?
    • What difficulties do you see for your projects?
    We will keep this thread open for a few weeks for a good discussion after which it will be closed.
     
  2. Tehenauin

    Tehenauin

    Joined:
    Oct 18, 2018
    Posts:
    45
    Hey! I accidentally stumbled upon this thread, because this is what I am looking for right now.
    Unfortunately rendering at the root level would not help in my case. I would rather like to only ignore the direct parent sorting group.

    Maybe an option to reference another sorting group which should akt as the new parent when Ignore Parent Sorting Group is enabled could help here. If nothing is referenced, it sorts on root level.
     
  3. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    356
    What is described by the OP is actually exactly what I need.

    What does your hierarchy look like?
     
  4. DungDajHjep

    DungDajHjep

    Joined:
    Mar 25, 2015
    Posts:
    202
    • How well does this solution fit your goals and objectives?
      100% fit

    • In what situations would it work well?
      Especially good for those gameobjects whose parents change.
      Examples 1: are items that can be picked up and attached to the gameobject player.
      Examples 2: Special particle effects with sortingLayer on top like your Glow example..
      ..vv

    • What difficulties do you see for your projects?
      Without this feature, I have to accept some defects in my game. The way to fix it is very time consuming or unsafe, so I voted for this feature.

      P/s: It would be Amazing if this feature is updated for 2019LST.
     
    MousePods likes this.
  5. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    I appreciate the need for bypassing sorting groups internally in the hierarchy. The solution provided might be a good short term solution. I do worry about the sprite sorting becoming more difficult or confusing to work with in the longer term with multiple sorting groups and figuring out what bypasses what. This creates a kind of bidirectional communication structure on the component.

    My initial thought would be to make sorting groups only affect sprite renderers set to a particular render layer. Then if needed multiple sorting groups could be added to handle each layer. So you may have multiple sorting groups at the parent level, but the component structure would remain unidirectional (only affects self/children transforms) and maybe a bit clearer? The downside to this of course is that currently layers in the 2D renderer add passes and overhead to the rendering. If that can be fixed or reduced I think layers are a clearer workflow to break up a group.
     
    Leo-Yaik likes this.
  6. DungDajHjep

    DungDajHjep

    Joined:
    Mar 25, 2015
    Posts:
    202
    One more example, I have a gun and it's a child gameobject in the gameobject player, it has a ammo_shell particleSystem.
    SortingGroup(Character) will cause the shells in the particle lying on the ground to be displayed on top of the player when player are below it. (2d sorting by Y position)

    Also I have a suggestion that it would be easier to release a test by creating a BypassSortingGroup.cs script instead of creating an option on it.

    sortingLayer2.PNG
     
    Last edited: Oct 2, 2021
  7. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Sorry for the total offtopic, but I wish someone told that to UGUI developers.
     
  8. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    356
    @rustum

    Just wondering if this is coming out in 2022.1 alpha or beta?
     
  9. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    Honestly, we desparately need 2D world space text. Having even the current 3D textmeshes within the sorting group of 2D sprites breaks batching, that's draw calls and set-pass calls, except fot the text.

    Making a card game is a nightmare because text can never sort properly and run efficiently.
     
    NotaNaN, dotsquid and DungDajHjep like this.
  10. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    It would be nice to have some way to ignore sorting parent group. In my project, I'm spawning a simple sprite which transform needs to be the same as the parent but at the same time, the spawned sprite needs a different sorting layer.

    Currently, I need to spawn this sprite somewhere else and then write a bit of code so it will follow a certain game object. With this feature, I would have a bit less work. Nice QoL.
     
  11. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    356
  12. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    436
    The 'sort at root' will be targeted for 2022.1. Appreciate for the continuous feedback!
     
    TomTheMan59 and NotaNaN like this.
  13. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    Thank you for all the feedback! We especially appreciate the use-cases as this helps us understand what you are making. We have factored all this into our planning and so I am going to close and unstick this thread. Thanks again folks! :)
     
Thread Status:
Not open for further replies.