Search Unity

  1. Unity wants to learn about your experiences working on a Unity project today. We'd like to hear from you via this survey.
    Dismiss Notice
  2. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice
  3. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Resolved Haptic feedback in XR

Discussion in 'XR Interaction Toolkit and Input' started by saifshk17, Nov 25, 2020.

  1. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    347
    Hi,

    Is there an explanation of how to achieve haptic feedback in XR.Interaction through a script?
     
  2. matty0187

    matty0187

    Joined:
    Oct 14, 2020
    Posts:
    2
    +1 I’d like to see an example of this too
     
  3. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    347
    In XR controller script you will find the below function:

    Code (CSharp):
    1. public override bool SendHapticImpulse(float amplitude, float duration)
    2.         {
    3.             if (inputDevice.TryGetHapticCapabilities(out var capabilities) &&
    4.                 capabilities.supportsImpulse)
    5.             {
    6.                 return inputDevice.SendHapticImpulse(0u, amplitude, duration);
    7.             }
    8.             return false;
    9.         }
    So assuming you want to call this function from your own script, do like this:
    Code (CSharp):
    1. private XRController xr;
    2.  
    3. void Start()
    4. {
    5.   xr = (XRController) GameObject.FindObjectOfType(typeof(XRController));
    6. }
    7.  
    8. void ActivateHaptic()
    9. {
    10.   xr.SendHapticImpulse(0.7f, 2f);
    11. }
     
    wm-VR likes this.
  4. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    104
    To add on to the previous response, that
    SendHapticImpulse
    method is part of the base
    XRBaseController
    class, so it will work for both the recommended Action-based Controller (
    ActionBasedController
    ) and the Device-based Controller (
    XRController
    ).

    There is also a convenience method on
    XRBaseControllerInteractor
    with the same signature which is used within that same class for doing haptic feedback on select and hover if you would like to look at an example.
     
  5. louspawn10

    louspawn10

    Joined:
    Dec 5, 2018
    Posts:
    3
    I am using Unity version 2020.2.1f1 and the above doesn't work when making a build on Oculus Quest even though it works on the Editor as a Rift using Oculus link. I get zero haptic feedback, any ideas? Does anyone else have the same problem?
     
  6. AstralStew

    AstralStew

    Joined:
    Jun 13, 2013
    Posts:
    3
    Yep, exact same behaviour here on Unity 2019.4.11f. Using ADB it seems that InputDevice.TryGetHapticCapabilities returns false on the Quest, but not in editor as Rift.
     
    wimachtendink likes this.
  7. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    104
    We don't know of any issues with haptic impulses not working with Quest. Please report this bug using Help > Report a Bug in Unity if you have a reproducible example.
     
  8. unity_Vvl3Urv06lpDmQ

    unity_Vvl3Urv06lpDmQ

    Joined:
    Mar 23, 2021
    Posts:
    1
    Same problem here. I figured out why.
    upload_2021-4-9_19-3-44.png

    with OpenXR it doesnt work for me. had to go back to Oculus
     
  9. Muskie

    Muskie

    Joined:
    Jan 21, 2017
    Posts:
    96
    That would be because, as stated in the Documentation for the OpenXR plugin, Haptics are not currently supported yet.
     
    chris-massie likes this.
  10. unity_f_BuZ-n1qXNO1A

    unity_f_BuZ-n1qXNO1A

    Joined:
    Apr 17, 2021
    Posts:
    1
    thanks
    I adjusted to what I needed, I made another script and implemented it in the righthandcontroller game object which contained the XRController class which was set for the right hand. so i get haptic for hand controller(Right Controller). I replaced: xr = (XRController)GameObject.FindObjectOfType(typeof(XRController));

    With: xr = GetComponent<XRController>();
     
unityunity