Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question UI Raycast through sprite mask

Discussion in 'Editor & General Support' started by salonso, May 27, 2020.

  1. salonso

    salonso

    Joined:
    Jul 24, 2018
    Posts:
    4
    Hi,

    I want to make a UI that applies a mask on it to make everything blur/darken and just a visible shape. To do this is simple just add a sprite renderer background with the screen size with alpha 0.5 and another object with a Sprite mask on it.

    This is the structure:

    UI Overlay: parent node that contains a Rect Transform and a Sorting group.
    -- Background Overlay: this contains a Sprite Renderer with a sprite 0.5 alpha
    -- Mask: Sprite Mask with the shape within.

    This is what I got:

    View attachment 630749

    But I want everything blur/darken to be NOT clickable and not getting the click-through and just make everything within the area clickable. Even things that go deeper into the hierarchy.

    I know if an "Image" is applied and then selects "Raycast target" then it blocks all clicks through but I cannot get the sprite mask.

    I tried to apply a script to the background to implement ICanvasRaycastFilter but I don't think it works with Images because nothing is being executed on the method that interface implements.

    Any ideas?

    Thanks in advance,

    Regards.