An option to ignore parent Sorting Groups Important Note:The functionality described here isnot availableand isnot 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.
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.
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.
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.
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.
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.
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.
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.
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!