playMaker

Author Topic: Set Sorting Group (Sprites)  (Read 2272 times)

Thore

  • Sr. Member
  • ****
  • Posts: 480
Set Sorting Group (Sprites)
« on: May 14, 2019, 03:06:10 PM »
There's a newish component for 2D, called Sorting Group. I've made an action that can set the two properties, the Sorting Layer and the Order in Layer.

In a nutshell, it "flattens" all the sprites under one Game Object so that they occupy just one Order in Layer. In the picture below you see that the whole character is drawn in order 0 on the "Default" sorting layer.



Quote from: Unity's Sorting Group description
Adding a SortingGroup component to a GameObject will ensure that all Renderers within the GameObject's descendants will be sorted and rendered together.

A common use case for having a SortingGroup is to create complex 2D characters that are made up of multiple SpriteRenderers. When several clones of such a character overlap, their individual body parts might not be sorted properly resulting in a visual glitch where the the body parts interleave. For example, the hands of two characters might be sorted in front of their bodies, where you would expect one entire character to be drawn in front of the other character. The SortingGroup component solves this by ensuring the entire branch of the character are sorted and rendered together.
« Last Edit: May 15, 2019, 11:54:20 PM by Thore »

PlaymakerNOOB

  • Full Member
  • ***
  • Posts: 219
Re: Set Sorting Group (Sprites)
« Reply #1 on: May 17, 2019, 11:50:22 AM »
Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Sorting Group (Sprites)
« Reply #2 on: May 23, 2019, 05:21:09 AM »
Hi,

 I took your action and updated it slightly, and it;'s now on the ecosystem.

the action is called: SetSortingGroupProperties

Check it out and see how I edited it, basically, you can use ComponentAction<> class to override and make component access easier and reliable with less code.

I also made similar actions for control the renderer component layer itself as well. RendererSetOrderInLayer and RendererSetSortingLayer

thanks for your input!

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Set Sorting Group (Sprites)
« Reply #3 on: May 23, 2019, 02:38:15 PM »
Superb, thanks a lot, Jean!  ComponentAction<> looks very useful, will certainly use it. Thanks.

I noticed a small typo in 86

Quote
return "sortingLayerName will be ignored, because orSortingLayerID is set";

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Sorting Group (Sprites)
« Reply #4 on: May 24, 2019, 01:53:28 AM »
Hi,

 fixed :)

 Bye,

 Jean