Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Get XR controller from PointerEventData? (Tooltip system)

Discussion in 'XR Interaction Toolkit and Input' started by R1PFake, Sep 3, 2022.

  1. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    507
    Hello,
    I have a ToolTip system which works with the IPointerEnterHandler and IPointerExitHandler interfaces.

    The events pass the PointerEventData class. Is there any way to use this information to detect which XR controller (left or right) caused the pointer event, so that I can show the tooltip in the correct hand?
     
  2. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    507
    I found the answer in a different thread:
    https://forum.unity.com/threads/whi...w-do-i-get-the-controller-being-used.1196866/

    Code (CSharp):
    1.     public void OnPointerEnter(PointerEventData eventData)
    2.     {
    3.         if (eventData is TrackedDeviceEventData trackedDeviceEventData)
    4.         {
    5.             if (trackedDeviceEventData.interactor is XRBaseControllerInteractor xrInteractor)
    6.             {
    7.                 // Your code, for example haptic or compare the interactor to left / right
    8.                 xrInteractor.SendHapticImpulse(0.25f, 0.25f);
    9.             }
    10.         }
    11.     }
    12.  
     
    LyraJean and VRDave_Unity like this.