Search Unity

Question Haptics in OpenXR - how to send a pulse to a specific controller?

Discussion in 'VR' started by NemesisWarlock, Nov 29, 2021.

  1. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    140
    I'm currently upgrading our XR systems to OXR, and i've hit yet another roadblock.

    I've updated the Haptics code from the old system to using OpenXRInput.SendHapticImpulse() as described here:

    https://docs.unity3d.com/Packages/c.../UnityEngine.XR.OpenXR.Input.OpenXRInput.html

    Sending an impulse works, but it sends it to both controllers, even though I've set the specific InputActionReference to the Haptic device outputs.

    SendHapticImpulse() has a parameter to pass in a Input Device, but it uses InputSystem.InputDevice. From what i'm aware, XR controllers require UnityEngine.XR.InputDevice. How do I get the Correct device to pass in, here?
     
  2. DylanF

    DylanF

    Joined:
    Jun 25, 2013
    Posts:
    55
    Try something like this:

    Code (CSharp):
    1. var device = InputSystem.GetDevice<XRController>(CommonUsages.RightHand);
    2. var command = UnityEngine.InputSystem.XR.Haptics.SendHapticImpulseCommand.Create(0,amplitude,duration);
    3. device.ExecuteCommand(ref command);
     
    eovento likes this.
  3. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    140
    That's using the old method, I'm specifically asking how
    OpenXRInput.SendHapticImpulse()
    works.


    Besides, the first line of the code you provided won't even compile:
    CS0311    The type 'UnityEngine.XR.Interaction.Toolkit.XRController' cannot be used as type parameter 'TDevice' in the generic type or method 'InputSystem.GetDevice<TDevice>(InternedString)'. There is no implicit reference conversion from 'UnityEngine.XR.Interaction.Toolkit.XRController' to 'UnityEngine.InputSystem.InputDevice'.  
     
    Last edited: Nov 30, 2021
  4. zachdavis0099

    zachdavis0099

    Joined:
    Nov 1, 2021
    Posts:
    2
    +1 I've been struggling with the same thing.
     
  5. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    140

    I've managed to sort this one out. UnityEngine.InputSystem.XR (As opposed to just plain InputSystem, watch out for this one) has the appropriate InputSystem.InputDevice to pass through to OpenXRInput.SendHapticImpulse.

    Code (CSharp):
    1.  
    2. [SerializeField] InputActionReference leftHapticAction;
    3. [SerializeField] InputActionReference rightHapticAction;
    4.  
    5.  
    6. OpenXRInput.SendHapticImpulse(rightHapticAction, amplitude, duration, UnityEngine.InputSystem.XR.XRController.rightHand); //Right Hand Haptic Impulse
    7.  
    8.  
    9. OpenXRInput.SendHapticImpulse(leftHapticAction, amplitude, duration, UnityEngine.InputSystem.XR.XRController.leftHand); //Left Hand Haptic Impulse
     
    Yuki_Asakawa and Jonathan-Bro like this.
  6. Gerrielofo

    Gerrielofo

    Joined:
    Mar 1, 2022
    Posts:
    1
    This doesn't return any errors for me but is still doesn't work. I am using the Quest 2.

    edit: I it's my bad, I thought my group was using OXR but it turns out we're using OVR.
     
    Last edited: Dec 21, 2022
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    What are the units for amplitude and duration? The docs do not say, and I haven't yet been able to find a specific example.
     
  8. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    Amplitude should be [0-1] where 1 is max. (similar to volume)
     
  9. RogueStargun

    RogueStargun

    Joined:
    Aug 5, 2018
    Posts:
    296
    Thank you good sir. You have succeeded where AI has failed :)