Search Unity

Question UI Aware Raycast

Discussion in 'UI Toolkit' started by PeterVoss, Feb 28, 2021.

  1. PeterVoss

    PeterVoss

    Joined:
    Apr 12, 2020
    Posts:
    4
    I am using UI Toolkit and I want to know whether the mouse pointer is above a UI element (VisualElement) to ignore any other in game hover effects on objects that are behind the UI element. Also I don't want to trigger any in-game actions, when I for example click the mouse button on an UI element.

    How I can I find out whether my mouse button is over an UI element? The Physics.Raycast(...) certainly ignores the UI elements and cannot be used. The old UI system had a GraphicRaycaster that could figure this out. But how would I do this for UI Toolkit? Is there a similar concept that I haven't found, yet?

    Thanks for any help.
     
  2. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
  3. PeterVoss

    PeterVoss

    Joined:
    Apr 12, 2020
    Posts:
    4
    Yes, thank you. I just realized myself that I can probably just track all UI elements myself and then check if the mouse position is in the rect of the element. This should be easy and straight forward. The post that you have referenced is exactly what I was looking for. Thanks for sharing.
     
    Midiphony-panda and MousePods like this.