Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Haptics not working with OXR + XR Interaction Toolkit ()

Discussion in 'XR Interaction Toolkit and Input' started by SpaceOwlGames, Apr 30, 2021.

  1. SpaceOwlGames

    SpaceOwlGames

    Joined:
    Apr 22, 2016
    Posts:
    61
    Hello,
    I am trying to get haptic feedback working with the new XR Manager and Input System. All the other controls (tracking and buttons) work fine. I am using OpenXR for its universal compatibility since this project is for Vive Wands, Index, Oculus Touch and WMR. This is my setup:

    - Unity 2020.3
    - XR Plugin Manager 4.0.1
    - OpenXR Plugin 1.9.0
    - XR Interaction Toolkit 1.0.0-pre.3
    - XR Interaction Default Input Action Sample
    - Oculus Rift + Touch Controllers

    I have added the XRI Default Left + Right Controler (Preset) to the ActionBasedController defaults and added the Left/Right filter to the Preset Manager. I have added an Input Action Manager to the scene along with the XR Rig. This is the example test controller script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR;
    5. using UnityEngine.XR.Interaction.Toolkit;
    6.  
    7. public class ExampleHandController : MonoBehaviour
    8. {
    9.     public ActionBasedController xrc;
    10.     public InputDeviceCharacteristics deviceChar;
    11.     public InputDevice device;
    12.     public bool assigned;
    13.  
    14.     // Update is called once per frame
    15.     void Update(){
    16.  
    17.         //look for matching device when it wakes up
    18.         if (!assigned) {
    19.             var devices = new List<InputDevice>();
    20.             InputDevices.GetDevicesWithCharacteristics(deviceChar, devices);
    21.  
    22.             if (devices.Count > 0) {
    23.                 Debug.Log($"{devices.Count} devices found for {deviceChar}");
    24.                 device = devices[0];
    25.                 Debug.Log($"device {device} assigned");
    26.                 assigned = true;
    27.             }
    28.         }
    29.         //trigger press
    30.         bool triggerValue = false;
    31.         if (device.TryGetFeatureValue(CommonUsages.triggerButton, out triggerValue) && triggerValue) {
    32.             Debug.Log("trigger down");
    33.  
    34.             //METHOD 1: LEGACY INPUT
    35.             HapticCapabilities capabilities;
    36.             if (device.TryGetHapticCapabilities(out capabilities)) {
    37.                 if (capabilities.supportsImpulse) {
    38.                     Debug.Log($"supports impulse");
    39.                     uint channel = 0;
    40.                     float amplitude = 0.5f;
    41.                     float duration = 1.0f;
    42.                     bool result = device.SendHapticImpulse(channel, amplitude, duration);
    43.                     Debug.Log(result); //this is FALSE, no idea why
    44.                 }
    45.             }
    46.         }
    47.  
    48.         //grip press
    49.         float gripValue = 0;
    50.         if (device.TryGetFeatureValue(CommonUsages.grip, out gripValue) && gripValue > 0.5f) {
    51.             Debug.Log("grip down");
    52.  
    53.             //METHOD 2: use built in hapticimpuse
    54.             /*https://forum.unity.com/threads/haptic-feedback-in-xr.1011787/#post-6899309*/
    55.             bool result = xrc.SendHapticImpulse(0.7f, 2f);
    56.             Debug.Log(result); //this is TRUE but no rumble
    57.         }
    58.     }
    59. }
    I am attempting to get a haptics response via the TRIGGER or GRIP using two methods I found online:
    TRIGGER (Method 1): https://docs.unity3d.com/Manual/xr_input.html#Haptics
    GRIP (Method 2): https://forum.unity.com/threads/haptic-feedback-in-xr.1011787/#post-6899309

    Both fail. I am not sure why. Does anyone that has more experience with OpenXR be able to help me?

    I have setup a demo project that has these settings / setup to demonstrate the problem:
    https://drive.google.com/file/d/1BcILkoOpoBup_ZyyyDHVr8_TLLNiwxRF/view?usp=sharing
    Check out the scenes/samplescene for my demo.

    Thank you!
     
  2. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
  3. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Looking at your script I think all you have to do is use channel 1 instead of channel 0 until the next version of OpenXR comes out. That being said I did not try your script so there could be other issues that I am missing, but give that a try.
     
  4. SpaceOwlGames

    SpaceOwlGames

    Joined:
    Apr 22, 2016
    Posts:
    61
    Thanks, the new update of OpenXR 1.2.0 fixes the channel back to zero. Haptics now works for Oculus Touch and Knuckles controllers. However, testing with HTC Vive Wands controllers do not register that it supports impulse:
    Code (CSharp):
    1. public void TriggerHapticPulse(float duration, float amplitude) {
    2.         Debug.Log($"haptic {duration}/{amplitude}");
    3.         HapticCapabilities capabilities;
    4.         if (device.TryGetHapticCapabilities(out capabilities)) {
    5.             if (capabilities.supportsImpulse) {
    6.                 Debug.Log($"supports impulse");
    7.                 uint channel = 0;
    8.                 bool result = device.SendHapticImpulse(channel, amplitude, duration);
    9.             } else {
    10.                 Debug.Log($"no impulse support");
    11.                 xrc.SendHapticImpulse(amplitude, duration);
    12.             }
    13.         }
    14.     }
    The result is "no impulse support" and the wand controller does not buzz at all even with the xrc.SendHapticImpulse
    Any ideas on why this is the case?
     
  5. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    I looks like the HTC vive interaction feature is missing a haptic output in it. We will add this in but in the mean time if you want to get it working your only option would be to duplicate the HTC vive interaction feature in your own project and add the haptic output to the ActionMapConfig yourself. Then you would just use your feature instead of the built-in one to get it to work. Feel free to private message me if you want help getting this working. In the mean time we will get that fixed on our end.