Unmask a sprite with a quad mesh in runtime

I want add eyes on my 2d characters. I want to achive different emotions by changing the eye shape. So my solution is Put the eye as a sprite and create a dynamic quadmesh on it. Only the part of the eye will be visible which is under the quad mesh. Tried to explain it with a picture :slight_smile:133270-untitled.png

How can i achive this. If i apply the eye texture as a material to the quad mesh, moving the vertices also distords the image and not hiding it…How can i mask/unmask a part of the texture/sprite with a quad mesh?

Hi,

You can create an image on runtime, where you get your quad vertices and fill them in a .png. Set this png as the sprite in a sprite mask. Then configure your eye sprite to be visible under mask.

As “drawing a png” is pretty messy, I recommend you to use a render texture. Use an additional camera that only renders a certain layer (i.e. your quad) onto a texture. Use this texture as the input into your sprite mask. If you now change your vertices, it will get updated/redrawn automatically.

Sidenote: if you move your quad to an extra layer, you can make your main camera ignore that layer. The quads will then be invisible in your game view