I have a sprite that takes up the entire screen that I want to mask with multiple rectangles. I also want to animate those rectangles.

So far, the only thing I've found is to make the sprite a child to the rectangle and clip the children.

There are 2 problems I've encountered with that so far.

  1. can only mask with 1 item as it's the parent.
  2. as soon as I move the left corner, the child sprite starts to move with it (not locked into the world position).

Is there a better way to mask sprites (or textures)?

cybereality
Hey, thanks man! I'm checking it out. But I can't really wrap my head around how this would be used in practice. I understand that CanvasGroup "merges" the children together to draw them as 1 item. So far, so good (if I understood it correctly). But how would I use that to mask/clip a single sprite? How would the nodes hierarchy look like?

Are there any examples somewhere I can see it in action?

Draw mask rects with a shader that uses screen UVs to sample the masked texture.

2 months later

This seems a lot more complicated than it was in 3.X where the scene structure didn't matter.

@cybereality
You can't make a CanvasGroup a mask because the children of the canvas group make up the canvas group, the CanvasGroup on it's own also has no texture input to be used as the mask's shape and clip_children only affects the children of the node with clip_children enabled.

Seems as though it is impossible to to have multiple separate mask nodes affecting the same node. Maybe if you use a subviewport that records the mask shapes to generate a texture somehow. Though that's way more trouble than it's worth.