To hide parts of sprites, add a sprite mask to the scene. You place a sprite mask at a position in the scene, and the mask shape hides the sprites that overlap with it.
Sprite masks only affect objects that have a Sprite RendererA component that lets you display images as Sprites for use in both 2D and 3D scenes. More info
See in Glossary component.
Note: Sprite masks are different to the mask map texture you add as a secondary texture to control which areas of a sprite receive light.
Sprite masks aren’t compatible with the following:
Follow these steps:
In your 2D renderer asset, make sure Depth/Stencil Buffer is enabled.
To add a sprite mask to the scene, select GameObject > 2D Object > Sprite Mask.
The default mask shape is a circle.
In the Hierarchy window, select the sprite you want to mask.
In the Inspector window of the sprite, set Mask Interaction to Visible Inside Mask or Visible Outside Mask.
Make sure the sprite overlaps with the sprite mask.
To change the shape of a mask, follow these steps:
To use a custom shape, create a new sprite with the shape you want to use. Use opaque pixels for the mask shape, and a transparent background for outside the mask.
To change which sprites a mask affects, assign the sprites to sorting layers, then restrict the sprite mask to a range of sorting layers using its Custom Range properties.
For example:
You can also use Sorting Group components to prevent multiple masks from interacting with each other.