Search Unity

Bug UIInputModule checks Cursor.lockState when used with TrackedDevice

Discussion in 'XR Interaction Toolkit and Input' started by Tha_Fuerst, Mar 15, 2023.

  1. Tha_Fuerst

    Tha_Fuerst

    Joined:
    Oct 19, 2018
    Posts:
    8
    (XRInteractionToolkit 2.2.0 Unity 2021.3.18f1)

    I've discovered that I can't scroll UI-ScrollRect in my Application so I digged a little bit into the UIInputModule code. Since the same method

    Code (CSharp):
    1. void ProcessPointerButtonDrag(PointerEventData eventData, float pixelDragThresholdMultiplier = 1.0f){...}
    is also used when processing Mouse or Touch - there is a check for Cursor.lockState in the first line.

    In my app I'm only using RayInteractor and my Cursor is deactivated and locked so this line prevents any UI drag events.

    Currently my fix is to add a new Parameter

    Code (CSharp):
    1. void ProcessPointerButtonDrag(PointerEventData eventData, float pixelDragThresholdMultiplier = 1.0f, bool checkCursorLockState = true){...}
    and change the first line from

    Code (CSharp):
    1.  
    2. if (!eventData.IsPointerMoving() ||
    3.                 Cursor.lockState == CursorLockMode.Locked ||
    4.                 eventData.pointerDrag == null)
    5.  
    to

    Code (CSharp):
    1.  
    2. if (!eventData.IsPointerMoving() ||
    3.                 ( checkCursorLockState && Cursor.lockState == CursorLockMode.Locked ) ||
    4.                 eventData.pointerDrag == null)
    5.  
    and changing the corresponding calls in the whole (UIInputModule) file. Where mouse is processed I call it with "checkCursorLockState = true". Where Touch and TrackedDevice gets processed I use "checkCursorLockState = false" - because I think on Touch you also don't want to check CursorLockState?
     
    Last edited: Mar 15, 2023
  2. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    275
    Hey @Tha_Fuerst,
    Great catch on this. I think your solution makes a lot of sense, especially considering that we try to limit the direct dependency on the newer Input System. Speaking of, I took a look at the
    InputSystemUIInputModule
    and how they handle the same case and it looks like there is an extension class for the
    eventData
    (ExtendedPointerEventData) that provides a
    pointerType
    so that can be checked instead of passing a bool into the function. I will chat with the team about pulling the ExtendedPointerEventData class into our XR flavor of InputModule to mimic the same behavior for consistency.