Add a sprite mask
Add a sprite mask to a scene, change its shape, and configure sprites so they're affected by the mask.
読み終わるまでの所要時間 2 分最終更新 1ヶ月前
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.

A circular mask, with a crate sprite set to Visible Inside Mask. The parts of the sprite outside the mask are hidden.

The same circular mask, with a crate sprite set to Visible Outside Mask. The parts of the sprite that overlap the mask are hidden.
Sprite masks only affect objects that have a Sprite Renderer component.
Limitations
Sprite masks aren't compatible with the following:
- Scriptable Render Pipeline (SRP) Batcher. If you use a sprite mask, Unity falls back to using dynamic batching.
- GPU deformation of sprites in 2D animation. If you use a sprite mask, Unity falls back to using CPU deformation.
Add a sprite mask
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 thewindow of the sprite, set Mask Interaction to Visible Inside Mask or Visible Outside Mask.Inspector
?
-
Make sure the sprite overlaps with the sprite mask.
Change the shape of a mask
To change the shape of a mask, follow these steps:
- Select the sprite mask GameObject.
- In the Inspector window, select the picker (⊙).Sprite
?
- Select a sprite from the list to use as a mask.
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.
Set which sprites a mask affects
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:
- Open the Tags and Layers window and create three sorting layers: Back, Middle, and Front.
- Create three sprites, and set their Sorting Layer properties to the different layers.
- Select your sprite mask, and in the Inspector window enable Custom Range.
- Set the front Sorting Layer to Front, and the back Sorting Layer to Back. The sprite mask now only affects the sprites in the Front and Middle sorting layers.
You can also use Sorting Group components to prevent multiple masks from interacting with each other.

Left: Two sprite masks affect two card sprites, so the sprites overlap incorrectly. Right: Each sprite and its mask use their own sorting group, and the sprites overlap correctly.