Tell us how you're using the Sorting Group Component

Hiya everyone!

The 2D Team at Unity is researching future developments for the 2D feature-set.

To begin with we are looking at the foundational pieces. One of these is sorting. Specifically we’d like to get a better understanding of how everyone is using Sorting Groups.

4284103--383461--Sorting Group Component.png

Here are some questions to get this discussion started:

  • Are you using the Sorting Group component?
  • If so, how are you using it? What problem are you solving using Sorting Groups?
  • Are you using nested Sorting Groups?
  • If so, how are you using them? What problem are you solving using nested Sorting Groups?
  • If we removed the ability to nest Sorting Groups, how would this impact your productions?

If you would rather answer these questions in private, please follow this link to answer a short survey.
Sorting Group Component - Usage Survey

We’re looking forward to hearing from all of you!

Hey Rus.

I’ve been using “nested” sorting groups .
I have characters made up of several pieces (arms, body, head etc.) in a sorting group called “character meshes” and then have that character in a parent object which uses the sorting group component to set the character into a “World” layer in a 2D map . From there I have a simple script that sets the Order value based on the Y position.
This way all characters are placed in the same sorting group layer and are correctly order sorted for moving on the map.

I’ve no real issues with this as it is but I’d love if you could set an enum if you wished to pass in the transform to the order value .

1 Like

This has actually reminded me about this feature! I will definitely be using it on current project to fix a couple of sorting issues (characters holding weapons). I won’t be using nesting but I can see the value there.

1 Like

I’ve only started using this. I have a 2D top down (like zelda) where my character can walk behind objects like trees and walls. I’m using multiple sprites for body parts and weapons so this is great to stop my character’s body parts fighting with the trees :slight_smile:

3 Likes

Doing top down games I put sorting group components on character-parent(while the child objects just use sorting with sprite property) and objects like trees, bushes etc. so the character can sort with those when walking in front and behind.
No problems so far and don’t really have any suggestions on how to expand the function.

2 Likes

I actually stumbled across this component accidentally. I’m using the Anima2D skeletal animation framework which, similar to some of the other posters, composites multiple sprites to make up a complete character. Each of these sprites uses their own “order in layer” value which is fine until I pull Unity’s 2D tilemap system into the mix. I’m using isometric tilemaps and custom axis (y-axis) sorting which works great unless you have a skeletal character with different body parts with different order values. I just started searching through components for something that sounded like it might solve my problem and found the Sorting Group. Brilliant!

On a side note, I was also playing with the Unity 2D Animation Package preview which actually feels pretty good (and it’s native), but I’ll probably wait until it goes full release to commit to it. I’ve also only been playing with game dev for a few months so maybe take my endorsement with a grain of salt.

1 Like

This is amazing. Found out about this by accident, too, immense time and sanity saver for me. Works perfectly for my purposes. I’m using it to group characters and props together, so they are drawn as one complete entity. This is important, because it would otherwise be almost unmanageable once you have multiple characters each made of out different sprites, and you cannot just shove them to different layers.

1 Like

This has saved my project basically. I have a Grid Generator custom tool that would use a hex sprite prfab to make a flat top hex grid in the editor. I set the renderers sorting order and in editor it looked exactly how it was supposed to, but as soon as i hit play all of the cells would reorder themselves and ruin the map i had just made(many of the sprites are larger than the Hex). I finally saw this thread and just added a sorting group when i instantiated my grid and it fixed it. the cells now keep their rendering order when i play the scene. My project would have ended there without Sorting Groups.

I now have what I think is a bug with Sorting Group. For one, my setup behaves ‘differently’ now for no apparent reason, than it did a few days ago. I am not aware I made changes, but I might be mistaken. Restarting has no effect.

Bug Description
Sorting Group has no effect (anymore) when a game object with sprite renderers is put as child under it during runtime, but takes effect when (in runtime) Sorting Group is briefly disabled and enabled again.

I have a prefab with a Sorting Group, let’s call it Item. I have a character who has a Holder game object also with a Sorting Group. In runtime, the Item is created from the prefab, and parented into the Holder. What should happen is that the Holder’s Sorting Group determines where the Item is being rendered (namely to look as if carried by the character). This worked, but now the Item is rendered above everything else, somehow ignoring its parent’s Sorting Group(s). I can disable and re-enable the component in runtime, and then it renders correctly. I see no difference when I remove the Sorting Group component on the item itself (I would need it when the item is dropped into the level, i.e. not carried around).

I might be doing something wrong. Let me know, to avoid (and fix) this issue, thanks :slight_smile:

Edit: the issue disappeared, but I have no idea why (I did some refactoring on input and handling of the flipping, which also touches on parenting objects around).

I have been using the sorting group feature mainly for making sure that certain sprites appear on top of other sprites, for example a top down game where when the player walks behind the top half of a building the player sprite would be on a lower sorting layer than the top of the buildings to make sure the player is rendered behind the building.
I have also used this to make sure weapons are always rendered on top of enemies so that when attacking the weapon layer sprites don’t compete with the enemy layer sprites.

Check out this video and especially from 3mins onwards, sorting based on an axis which might be suitable for your game.

https://www.youtube.com/watch?v=q-r1YJzj28M

1 Like
  1. Yes, actively in our most recent project.
  2. The game is a 2D side-scroller and we put the sorting group on character root and other prefabs such as a building root that has multiple children. The big problem in Unity is adjusting the sorting order and layer for hundreds or even thousands of objects in a scene. When one order changes hundreds of other objects may need to be changed. Sorting Groups helps keep these changes more localized, because now we only have to sort characters and buildings against each other while keeping the attached children, e.g. windows and decorations within the sorting group.
  3. We used it at some places initially but then found it a little bit too confusing and tried to limit the use of Sorting Groups to prefab roots close to the top-level or our hierarchy.
  4. Initially, we thought we could simply build some kind of hierarchy with sorting groups which would help us sort large scenes, but we soon realized that it got confusing as to which renderers were sorted against each other and which were part of a sorting group, so we stepped back and only use groups for the top-level prefab roots now.
  5. Not so much. We would actually slightly benefit from it because our custom tooling would become simpler. If overall performance would also benefit, we would welcome removing nested groups in favor of having a more easily understood sorting hierarchy with only one group per level.

Overall, we really like the Sorting Group component, but we could do without the ability to nest them.

  • Yes, a lot.
  • In current project we have several parallax layers of environment each of which has a Sorting Group. Sorting Groups allow us to manage draw orders of complex objects with ease.
  • Yes.
  • The objects in each parallax layers can be complex and consist of many Sprite Renderers. Sometimes we need to change the draw order of these objects inside the layer. Without nested Sorting Groups it would be a pain.
  • Please don’t.

absolutethosehart

2 Likes
  1. trying to sort sprites in top down view, by setting sordingOrder based on Y (and sometimes also X) coordinates.
    (image: eyes and mouth are separate child sprites. User can pickup bomb and need to be drawn on top in that case, by switching sortinglayer. Gets too complicated fast…)
    4708727--444845--upload_2019-7-3_10-13-13.png
  2. never heard

That’s actually stunning! It really saves me a great deal of time and nerves. And it’s just it for the needs I have :slight_smile:

My main issue with sorting groups is it doesn’t ‘work’ when combining Sprite Renderer and Image components. Both of these should ‘use’ sorting correctly

No, what’s that?

1 Like

Thank you. It looks interesting but I don’t think I would have some use for it.

Sorry to be reviving an old thread. And I submitted my replies, either way through the form.
But I have a question - why can we not record the sorting group sort order to the Mecanim?
We can record sprite renderer’s sort order, but not the sorting group.
Kinda defeats the purpose of it, for me.