thanks but i cant do that in my case, i needed to use 2 mask
the shapes i posted are a simplification, in truth the 2 masks are complex shapes that change every frame, I need a way that I can interact with 2 sprite mask
or a way that I can use mask 2 to mask mask 1? To create the shape that you showed, but in runtime
I’m not sure that’s possible with the sprite and sprite mask settings out of the box. But you can probably do it with shaders. Have you looked into Shader Graph? It makes it semi-intuitive to write shaders visually, without coding
So the main idea is to replace Unity’s Sprite Mask with custom, own versions of the built-in sprite shader. It’s less complicated than it might seem. Basically you take the sprite shader from Unity sources, and add the stencil functionality. You can find the source code from the download archive:
Then you can render first a base mask and write to the stencil buffer, and after that a mask that cuts out from the base mask. Now you can move the masks independently.
And if you really need some complex mask that changes every frame (and it’s procedural or something like that) you probably have to render it to a RenderTexture, then read by using ReadPixels and store the result to a Texture2D and then make a Sprite out of that Texture2D using Sprite.Create() function. But that ReadPixels is pretty slow so I would definitely try to find better solution (maybe generate the mask procedurally inside the shader(s) if it would fit your use-case.