SpriteMask in conjunction with SortingGroup does not work anymore

,

I am using Unity 2022.3.7 and experience a bug or maybe a not supported behavior using SpriteMask and SortingGroup in conjunction.

First let me explain what I use the SpriteMask for: I have a large projectile (rocket) shot out of a weapon a unit is wielding. While the projectile is spawned within the weapon, I want it to get visible when it moves and leaves the weapon sprite. Using simple sortingLayer/sortingOrder would also cause the projectile to get behind other scene game objects, so I decided to use a SpriteMask so it is only hidden at the weapon spot. This worked quite well.

Now I wanted to introduce a SortingGroup for my units because I run short on sortingOrder numbers on a specific layer (restricted by 65536 available sortingOrder numbers per sorting layer). The SortingGroup component seems to solve that issue so I can use much more different sortingOrder numbers per unit. But with the introduction of the SortingGroup it removes the SpriteMask effect, so it does not work anymore. I can reproduce this pausing the game in play mode while firing a projectile and testing with and without SortingGroup enabled. Without the SortingGroup enabled masking works fine, but with enabled SortingGroup the masking does not work anymore.

ChatGPT insisted that SortingGroup and SpriteMask should work together according to Unity documentation. But it doesn’t at least in my project.

Here are some screenshots about the setup in the scene hierarchy:
Screenshots

So my question are:

  • Is this a bug or not supported?
  • Is there a workaround to get both components working together?
  • In case it is not supported and there is no workaround: How to get more sortingOrder numbers within a specific sortingLayer when SortingGroup cannot be used cause of that issue?

9479587--1332940--upload_2023-11-18_11-23-45.png

this is an intended behaviour, its a feature that a mask only affects objects that are on the same sorting group

so you need to put the mask inside the sorting group where the sprite that you want to mask is

this exists as a feature, so you can choose what masks affect which sprites, otherwise all masks would affect all sprites that had the masking options turned on

as an adendum, i see that you are getting messed up by too little sorting points, i would advise a workaround, use transparency sort axis to sort by Z, if you use z to sort you get infinity sorting values because z is a float, and so you can use 1,2 , 0.1, 0.0015, etc

1 Like

Okay, thanks for explaining the “feature” and the transparency sort axis advice. I especially want to separate projectiles from units and only wanted to use SortingGroups for units so I can’t use SortingGroup then in this case. I will have a look into the transparency sort axis approach. Still it would require some effort to rework from sortingOrder to Z order.