- Home /
Prevent 2D mask to impact other gameobjects ?
Hi guys, I have several game objects with sprites that are using different 2Dmask but they seem to interact with each others.
I mean : object A with its own mask also masks object B (and they're not parenting whatsoever).
Is this expected behavior and how can I avoid this ?
Thanks
Answer by timzes · May 31, 2020 at 11:51 PM
I just set different sorting orders for my sprites and then attach fixing script to every mask:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FixMask : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
SpriteMask mask = GetComponent<SpriteMask>();
int so = transform.parent.gameObject.GetComponent<SpriteRenderer>().sortingOrder;
mask.isCustomRangeActive = true;
mask.backSortingOrder = so;
mask.frontSortingOrder = so;
}
}
Answer by gwelkind · May 22 at 05:55 AM
For anyone arriving here in 2022, the answer is sorting groups.
You'll want a sorting group component on the parent to make sure the mask only affects it's children, and not random other sprites associated with other game objects unrelated in the hierarchy.
Other answers here have not addressed users question, which is about isolating the effect of sprite masks
Answer by oussamahassini6 · May 22, 2018 at 05:00 PM
go check this vid https://www.youtube.com/watch?v=4pl8DcsCQ_k it might help
$$anonymous$$aybe I wasn't clear enough but this video didn't help at all ^^
$$anonymous$$y problem is the sprite used as a mask is actually masking all the sprites that I want to be masked by SPECIFIC $$anonymous$$AS$$anonymous$$S.
Right now any sprites using mask feature are all masked by the same mask which is not what i want : I want to use specific masks for specific sprites :)