Setting up a random generated masked path. (Unity 2020)

Hey guys! I am trying to set up a random generated path that the player needs to follow (kind like a labyrinth) between two points.

For that I set up random coordinates between position A and B and then I have simple squared images and hitboxes that I scale and rotate to fill the distance between each point. Something like this:

7051471--836617--upload_2021-4-18_11-31-20.png

Now. As the player moves through this path a image is supposed to be revealed inside the path and here is where the problems start.

1st. I can’t seem to use all these paths to mask a single image because the image needs to be the child of the mask so I can only have one mask at a time.

So I tried adding the same image to every single rectangle which complicated things because the paths they are all in different scales, positions and angles.

The scale and position of each image was easy to revert so they are all pixel perfectly aligned and then masked by their own path, but the rotation is being problematic.

I tried rotating the image back to it’s world Quaternion.Identity but for whatever reason the image inside the rotated parent is always distorted.

I also tried using Parent Constraint with a source from an point outside the parent, but the effects were the same.

I also saw some logic for editing masks so they will show the image outside it and not the image inside it, but I can’t figure out if there is a code or logic to get masks from other objects.

So please help!
• Is there a way to set this up where the child can just ignore the parent rotation?
• Is there a way to get the mask from an object that is NOT the parent? So then I can keep the images outside the parent and still get the mask effect?
• Is there a way to use multiple objects as masks?
• If not with masks would there another approach to this?

Thank you for the attention!

I m not entirely sure if I fully understand the problem but:

• Is there a way to set this up where the child can just ignore the parent rotation?

not that I know off

why is it a child anyway, the SpriteMask also works if the masked object aint a child
SpriteMask doesnt require parenthood what-so-ever

• Is there a way to get the mask from an object that is NOT the parent? So then I can keep the images outside the parent and still get the mask effect?

yes, SpriteMasks work beyond parenthood, you dont need to set it up as a child of the mask in the first place

if a sprite has Mask Interaction toggled on, it will use any mask that is enabled in the entire scene, no matter the relationship to it (unless you filter it with Rendering Layers, than it gets only masked if the mask has the same layer)

• Is there a way to use multiple objects as masks?

yea, simply have multiple objects with the SpriteMask component

• If not with masks would there another approach to this?

what I often do is to make a custom shader in which I input a Mask texture that gives the shader the alpha information for the sprite
though if you need the mask to not perfectly align with the sprite position, you will have to caluclate some offset vector and scale from the parenthoods (which is the main reason the SpriteMask component is easier compared to using an alpha mask in a shader)

Edit: here in a picture:

this should also answer your question about:
“I also saw some logic for editing masks so they will show the image outside it and not the image inside it, but I can’t figure out if there is a code or logic to get masks from other objects.”

see Mask Interaction on the right, can be toggled from None to Inside and Outside Mask