Search Unity

Feedback Support an IsOverGUI bool or something similar in the new InputSystem

Discussion in 'Input System' started by Thimo_, Jun 23, 2021.

  1. Thimo_

    Thimo_

    Joined:
    Aug 26, 2019
    Posts:
    59
    Currently im trying to create a behaviour for mobile. I want a screen wide tap interaction that one of my methods listens to. However, if I press a button or other UI element I want this tap event to stop triggering the moment I start pressing a button. This is currently not possible natively. I think having a bool that checks wether the user has pressed an UI elment is super useful in certain situations. I couldnt find anything on that its already implemented?

    Code (CSharp):
    1.  public static bool IsPointerOverUIObject()
    2. {
    3.      PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
    4.      eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
    5.      List<RaycastResult> results = new List<RaycastResult>();
    6.      EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
    7.      return results.Count > 0;
    8. }
    The above code is the go to solution I've used multiple times. But LeanTouch has it built in under Finger.IsOverGui. Is there something like this already in the new input system build in? If not I think its something small to add but really useful.
     
    josefgrunig likes this.