Search Unity

Question How to add sprite mask to a sprite skin?

Discussion in '2D' started by kevincicero98, Jan 7, 2023.

  1. kevincicero98

    kevincicero98

    Joined:
    Apr 14, 2020
    Posts:
    4
    Hi, I'm trying to add the sprite mask component to my animated sprite but it let me choose only one sprite as a mask and there's no option for adding animation on the sprite mask. Is there any way to do this?
     
  2. Xiangting_Su

    Xiangting_Su

    Unity Technologies

    Joined:
    Sep 22, 2020
    Posts:
    253
    Hi @kevincicero98, good news! We have implemented the support for Animated Sprite Mask in 23.1 together with some other 2D features.
    • Sprite Renderer
      • 9-Sliced
      • Animated
    • Tilemap Renderer
    • Sprite Shape Renderer

    22.2 and Before:
    Sprite Masks on animated Sprites didn't work before 23.1. The Sprite Masks didn't follow the animation.
    22.2 Sprite Mask.png

    23.1 and After:
    Animated Sprite Masks now works and gets masked properly even if the Sprites are animated.
    23.1 Sprite Mask.png


    Just remember to change your Mask Source to Supported Renderers instead of Sprites if it isn't already automatically updated.

    However, if you are trying to animate your Sprite Mask itself, this is currently not possible in Unity. At least not that I know of. However, interestingly, I came across an Animated Sprite Mask YouTube Demo shared by another user.



    There's even a GitHub link where he shared his implementation. I haven't tried it myself though, but I thought it looks really promising and might hopefully point you in the right direction?

    Also, this How to Animate Sprite Mask in Unity 2D: 1 Minute Tutorial might be useful too.
     
    Last edited: Jan 9, 2023
    DragonCoder and kevincicero98 like this.
  3. kevincicero98

    kevincicero98

    Joined:
    Apr 14, 2020
    Posts:
    4
    Thank you very much, I'm so happy that you added it. I will try to transfer my project to the latest version and hopefully nothing will break
     
    Xiangting_Su likes this.
  4. Xiangting_Su

    Xiangting_Su

    Unity Technologies

    Joined:
    Sep 22, 2020
    Posts:
    253
    Most welcome! ;) Oh and regarding the upgrade, in my experience, some things do break unfortunately. (Sorry!) So maybe play around with the Sprite Masks in a new 23.1 project first to see if it's worth upgrading?

    Just note that 23.1 is still in the alpha phase, so it's not as stable as say, the 21.3 LTS version. Alpha versions are not finished products and are likely to contain bugs, so if you are still interested in upgrading, remember to do a backup first just to be safe.
     
    kevincicero98 likes this.
  5. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
    Just want to let you know this is not working in 2023.1.0b8 so be careful about upgrading. I reported the bug. Here is a video of how you can work around it in the editor…but it still breaks when you hit play

    https://www.veed.io/view/9c2e936d-7b19-436f-b45f-d08e7879f039?panel=share

    IN-35629
     
    Xiangting_Su likes this.
  6. Xiangting_Su

    Xiangting_Su

    Unity Technologies

    Joined:
    Sep 22, 2020
    Posts:
    253
    Thank you for highlighting the issue! And also for helping to report the bug.
     
    MousePods likes this.
  7. Nit_Ram

    Nit_Ram

    Joined:
    May 8, 2016
    Posts:
    27
    Is there any way to use a mesh as sprite mask? If not, is it planned to support this as a supported renderer? Would help greatly to create clean polygon masks.