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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question OpenXR/New input System, detect HMD removed?

Discussion in 'XR Interaction Toolkit and Input' started by eblavender, Apr 20, 2021.

  1. andorfy

    andorfy

    Joined:
    Oct 12, 2015
    Posts:
    24
    I have the same issue, but only in builds.

    In editor (Unity 2022.2.18) everything works fine when I'm using Quest 2 with a link cable. But when I'm make a build the userPresence.Started event is most of the times are not called (chance of workin is about 10%).
    Input System package 1.5.1

    Tested with Oculus XR Plugin 4.0.0 and with OpenXR 1.7.0, both do the same.
     
  2. CBHM

    CBHM

    Joined:
    Feb 12, 2019
    Posts:
    24
    Hi, I have a similar issue where the user presence always returns true on the Samsung Odyssey WMR headset, when the OpenXR runtime is set to WMR, but it works correctly when using SteamVR runtime.
    Is there a way to get the user presence correctly with WMR runtime?
     
  3. MaxwellLovellWPS

    MaxwellLovellWPS

    Joined:
    Jan 4, 2023
    Posts:
    9
    Update using Unity 2022.1.2f1
    Using the "user presence" input action described previously in thread works for both Valve Index and Quest 2 in Rift mode. However, I have not found any method to let it work on standalone Quest 2. I've also tried using a session open XR feature described in another thread which had the exact same results.
    InputDevices.GetDeviceAtXRNode(XRNode.Head); Hasn't worked for me either.

    Anyone have any luck?
     
  4. VisualiseJack

    VisualiseJack

    Joined:
    Dec 19, 2019
    Posts:
    3
    I've been grappling with this for some time. I've just revisited and I think I've found a way around it for Quest 2.

    I am using Unity 2021.3.4f1 with OpenXR. I do however have Oculus Integration package installed, but only the Platform, Spatializer and VR folders (to try and cut down on bloat). I have found that using OVRPlugin.userPresent within the update returns a bool if the user is present (aka at the light sensor). This works without having the OVRManager component and can be inputted in scripts away from the XROrigin. You can then use that bool to check for user presence.

    I'm just working on the code now but will publish once I have something working
     
  5. VisualiseJack

    VisualiseJack

    Joined:
    Dec 19, 2019
    Posts:
    3
    Here is my script with a countdown timer for when the headset is removed (so that I can restart the video the user will be watching in my use case)

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class DetectHeadsetPresenceView : MonoBehaviour
    4. {
    5.     bool isUserPresent;
    6.     bool presenceReset = false;
    7.     bool countingDown = false;
    8.  
    9.     [SerializeField]
    10.     // Set this to 0 if you don't want a timeout duration
    11.     float timeoutDuration = 10f;
    12.  
    13.     float count = 0f;
    14.  
    15.     void Update()
    16.     {
    17.         // Set user presence bool
    18.         isUserPresent = OVRPlugin.userPresent;
    19.         //Debug.Log("IS USER PRESENT: " + isUserPresent);
    20.  
    21.         // Reset countdown
    22.         if (isUserPresent && (countingDown || count != 0f))
    23.         {
    24.             countingDown = false;
    25.             count = 0f;
    26.         }
    27.  
    28.         // Begin the countdown
    29.         if (!isUserPresent && !countingDown && !presenceReset)
    30.         {
    31.             countingDown = true;
    32.         }
    33.         // Run the countdown
    34.         else if(!isUserPresent && countingDown && count < timeoutDuration)
    35.         {
    36.             count += Time.deltaTime;
    37.             //Debug.Log("Presence count: " + count);
    38.         }
    39.         // Countdown complete and call Absent event
    40.         else if (!isUserPresent && countingDown && count >= timeoutDuration)
    41.         {
    42.             GameManager.HeadsetPresenceController.OnUserAbsent?.Invoke();
    43.             countingDown = false;
    44.             count = 0f;
    45.             presenceReset = true;
    46.         }
    47.         // Call Present event
    48.         else if (isUserPresent & presenceReset)
    49.         {
    50.             GameManager.HeadsetPresenceController.OnUserPresent?.Invoke();
    51.             countingDown = false;
    52.             count = 0f;
    53.             presenceReset = false;
    54.         }
    55.         // Else, User is present
    56.     }
    57. }
    58.  
     
  6. Gabrio

    Gabrio

    Joined:
    Jan 31, 2016
    Posts:
    17
    Hi,
    I'm trying this solution, but on the Quest 2 it always returns true even when I remove the visor.
    Is there anything I can update to make it work?

    I'm using Unity 2021.7, OpenXR, XR Interaction 2.3.2
     
  7. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    228
    OpenXR for me also doesn't properly show userPresence (both for the InputActionReference or the TryGetFeatureValue(CommonUsage...) approaches).

    Switching to the OculusXR plugin though reports userPresence correctly through both approaches mentioned above.

    For OpenXR, I get constant true for the TryGetFeatureValue, while false for the InputActionReference.

    Using Quest 2 in Rift mode and will be using it with a Windows build.

    Not sure if the Meta Quest Support for OpenXR in Android mode works properly.

    PS: OpenXR also has a sort of pause-like behaviour when the proximity sensor of Q2 detects no user, which resumes when a user is present (mounted headset). On the other hand, OculusXR plugin does nothing of the sort.
     
  8. MaxwellLovellWPS

    MaxwellLovellWPS

    Joined:
    Jan 4, 2023
    Posts:
    9
    Did you do anything special to get the build to run on Quest? I get errors when trying to access OVRPlugin while using openxr, it can't find the DLL
     
  9. MaxwellLovellWPS

    MaxwellLovellWPS

    Joined:
    Jan 4, 2023
    Posts:
    9