Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Exclude UI objects from pointer interactions?

Discussion in 'UGUI & TextMesh Pro' started by llde_chris, Feb 13, 2015.

  1. llde_chris

    llde_chris

    Joined:
    Aug 13, 2009
    Posts:
    205
    Hi,

    I track PointerEnter and PointerExit events for a RawImage in my UI.
    Unfortunately, I have some ruler lines that are drawn on top of the image, and these are causing PointerEnter/PointerExit events when I cross over them.

    Is there a way to prevent UI elements from interacting with the pointer?

    Our current workaround is a to place another image on top of everything that catches the PointerEnter/PointerExit events; unfortunately it needs to have an active image component for it to catch events. We just set it to have an alpha of zero, but it's still wasting alot of fill rate and is a rather ugly hack.

    Any good solutions for this?
     
  2. llde_chris

    llde_chris

    Joined:
    Aug 13, 2009
    Posts:
    205
    *FACEPALM*

    It's in the FAQ.

    Just implement ICanvasRayCastFilter and return false.
     
  3. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,688
    or add a CanvasGroup component to the individual or container GO for the UI elements you want to block ray casts for with the "Blocks Raycasts" option
     
  4. llde_chris

    llde_chris

    Joined:
    Aug 13, 2009
    Posts:
    205
    Yup, that's first thing I tried, and it works. It's just CanvasGroup semantics are for more than just raycasts; didn't really check but it's potentially going to be slightly heavier w.r.t. rendering.