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

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:


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?

Try something like this:

var device = InputSystem.GetDevice<XRController>(CommonUsages.RightHand);
var command = UnityEngine.InputSystem.XR.Haptics.SendHapticImpulseCommand.Create(0,amplitude,duration);
device.ExecuteCommand(ref command);
1 Like

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'.

+1 I've been struggling with the same thing.

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.

[SerializeField] InputActionReference leftHapticAction;
[SerializeField] InputActionReference rightHapticAction;

OpenXRInput.SendHapticImpulse(rightHapticAction, amplitude, duration, UnityEngine.InputSystem.XR.XRController.rightHand); //Right Hand Haptic Impulse

OpenXRInput.SendHapticImpulse(leftHapticAction, amplitude, duration, UnityEngine.InputSystem.XR.XRController.leftHand); //Left Hand Haptic Impulse

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.

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.

Amplitude should be [0-1] where 1 is max. (similar to volume)

Thank you good sir. You have succeeded where AI has failed :slight_smile: