Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Sprite Mask & Mesh Renderer overlap issue

Discussion in '2D' started by Reizka, Mar 16, 2021.

  1. Reizka

    Reizka

    Joined:
    May 27, 2013
    Posts:
    11
    Hi,

    I have an issue on masking a 2D sprite properly in 3D environment. For some reason the mesh renderer messes with the mask making sprite visible. See the below pictures that I hope make the issue clearer. I've run out of ideas on how to fix this. I have tried group sorting and fiddling with custom layers on the mask, but no avail.

    To explain the picture below. The light green space is where the background meshrenderer exists. If this is not in the background sprite mask behaves correctly masking the sprite inside the card as shown on the right picture.

    My version of unity is 2019.4.21f1. If that makes any difference. I'd rather not update unless absolutely necessary as there is always a risk of stuff exploding...


    thank you in advance
    Drawing.png
     
  2. Bean_Office

    Bean_Office

    Joined:
    Jun 18, 2018
    Posts:
    14
    Why didnt you make the 2D sprites in the 2D preset?
     
  3. Reizka

    Reizka

    Joined:
    May 27, 2013
    Posts:
    11
    Hi, Sorry but I don't understand the question. Could you elaborate on what you mean by "2D preset"?
     
  4. Reizka

    Reizka

    Joined:
    May 27, 2013
    Posts:
    11
    Hi all, just giving this post a pump, as I still have this issue and am no closer to fixing it...
     
  5. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    did you try sprite renderer instead of mesh renderer

    can also try putting the mask inside a sorting group so it only affects things in that sorting group
     
  6. Reizka

    Reizka

    Joined:
    May 27, 2013
    Posts:
    11
    Hi, rarac

    The sprite mask is in fact inside a sorting group. I took a couple of new images that I hope make it more clear.

    The background is a 3D object, hence the mesh renderer. The card root (3th image) has several spriterenderers inside of it and the sorting group is in the root Card gameobject. The card has several sprite renderers and a mask (4th image) and the sprite it should affecting (5th image)

    Now what I do know is that the mask issue has something to do with materials used. I did manage to get the card to work properly if I used some custom materials with custom shaders on gameobjects, but replacing all like this is a lot of work and some 3D meshes use more complex material schemes. I should be able to get this to work by only editing the card not all other gameobjects around it...

    My solution for now is quite ugly. I just make the images smaller, instead of relying on the mask to do its job. I just wonder whether this might be a bug in unity that is solved if I update to a newer version. Currently working on 2019.4.22f1...

    Screenshot 2021-04-06 at 15.07.00.png Screenshot 2021-04-06 at 15.07.23.png Screenshot 2021-04-06 at 15.08.04.png Screenshot 2021-04-06 at 15.08.35.png Screenshot 2021-04-06 at 15.08.44.png