- Home /
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 :)
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?
Answer by Klarzahs · Feb 18, 2019 at 12:03 PM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220612191853im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mesh Clipping / Cross Sections 1 Answer
Triplanar surface shader not responding to Mesh.Colors 0 Answers
Make transparency ignore meshes inside? 1 Answer
How to get a sphere surface with a solid angle through script? 1 Answer
Simple mesh deformation : Mesh.vertices or vertex shader with displacement texture ? 1 Answer