Are sprite masks incompatible with Render Textures?

Hello everyone,

I’ve just noticed on a new project that Sprite Masks don’t seem to work when the camera renders to a texture via a Render Texture target. Everything works just fine on the Camera and in-editor views, but the RenderTarget texture appears as though neither the masks nor one of my custom shaders are active.

The custom shader that isn’t working correctly makes use of the stencil buffer. Thus, I’m assuming the stencil buffer is the culprit and that the built-in Sprite Masks are implemented with the stencil buffer.

Is this a bug? Intended behavior that I’m misunderstanding?

I haven’t tried writing the pixels from the Camera over to the texture myself yet as I’m about to head to bed, but that’s what I’ll try next. Figured asking here might save me some time and effort tomorrow with any luck :slight_smile:

Any insight is appreciated. Thank you all!

I know this is old but I stepped into this problem now with Unity 2020 and I could solve it by changing “Depth Buffer” into RenderTexture object on Project Tab to “At least 24 bits depth (with stencil)”

I hope this helps!

Faced the same issue, solution by @AdayMelian is working for me.

More details:

  • "Sprite Mask" Layer and "Sprite" Layer need to be the same, for example "exampleLayer".

  • Render Texture, change Depth Stencil Format from none to D32_SFLOAT_S8_UINT.

  • In Camera, Culling Mask, add "exampleLayer".

I am having the same problem.
Sprite Masks work fine in a normal camera… but don’t work when shown in a render texture.
Any solutions?
Cheers,
Dan

Hey, I know this whole discussion is pretty old, but I was having the same issue and I fixed it just by enabling Post Processing on the camera in the inspector.

If anybody out there is struggling with this, give that a try.

Did anyone ever come up with a solution to this? Tried the suggestions here without success. Trying to use a second camera and a render texture to set up a 2D procedural planet generation tool. Having the same issue stated here. Render texture quad and material works fine but it doesn’t work with sprite mask interactions.