Search Unity

Question OpenXR/New input System, detect HMD removed?

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

  1. eblavender

    eblavender

    Joined:
    Sep 4, 2017
    Posts:
    14
    Hi Peeps!

    We are currently going through the review process with Oculus and we are required to detect when a HMD is removed, in order to pause our game. We are using the latest Unity 2020.3, and OpenXR 1.1.1, and I cannot find an option in the Input Actions window to detect this? I can't seem to find anything in the forums either. Any help on this would be appreciated.

    Kind Regards,
    Ben
     
    SirMazius likes this.
  2. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    140
    I'm currently looking at this myself. you'll want to make a new input action for <XRHMD>/userPresence, however this seems to be a touch buggy, as it occasionally doesn't register the event. you'll also want your menu buttons to trigger the pause as well.
     
    eblavender likes this.
  3. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    What sort of issues are you seeing with userPresence?
     
  4. yarsrvenge

    yarsrvenge

    Joined:
    Jun 25, 2019
    Posts:
    87
    I set up an action for userPresence using the new input system. The event fires when the headset is put on, but not when it is taken off. This is using a Rift S and the Oculus XR plugin or the OpenXR plugin.
     
  5. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Could you send the binding text you are using for your action just so we can test your exact scenario? I will try it here locally in the mean time and see if I can reproduce it.. Thank you
     
  6. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Tested this locally with Oculus OpenXR on the Oculus Runtime and was able to reliably detect the value
    userPresence
    . The binding I used was
    <XRHMD>/userPresence
    and used the following code to detect the state.

    Code (CSharp):
    1. action.Enable();
    2. action.started += (ctx) => Debug.Log("UserPresence: true");
    3. action.canceled += (ctx) => Debug.Log("UserPresence: false");
    4.  
    May be something with your set up that I am missing, let me know. Hope that helps.
     
    mrphilipjoel and azevedco like this.
  7. yarsrvenge

    yarsrvenge

    Joined:
    Jun 25, 2019
    Posts:
    87
    Ah, I think. was using action.performed += and then checking the context for whether performed was true or false (never got false). Maybe that was the problem. I'll try what you posted.

    I think the docs said to set that binding up as a button...correct?
     
    xinuxano likes this.
  8. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Yes I bound it as a button.
     
    xinuxano likes this.
  9. yarsrvenge

    yarsrvenge

    Joined:
    Jun 25, 2019
    Posts:
    87
    That worked! Thanks!
     
    the_real_apoxol likes this.
  10. xinuxano

    xinuxano

    Joined:
    Feb 28, 2018
    Posts:
    33
    And for Valve Index ? Thanks
     
  11. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    That does not work on the index?
     
  12. xinuxano

    xinuxano

    Joined:
    Feb 28, 2018
    Posts:
    33
    I still haven't gotten it to work. I have added the input action XRMD / UserPresence (generic; I have not found anything particular for Valve Index). And it seems that it does not generate any events. Not when putting the headset on or taking it off. Does anyone have it working?
     
  13. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Can you share the script you are using for the actions?
     
  14. xinuxano

    xinuxano

    Joined:
    Feb 28, 2018
    Posts:
    33
    On Input Actions:
    Presence (Action Type = Button)
    Properties Binding = <XRHMD>/userPresence (Press And Release)

    Player Input script Behavior = Send Messages

    Script
    public void OnPresence(){
    Debug.Log("Hi");
    }
     
  15. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    I am not familiar with this player input script logic. Would you be willing to private message me a example project so we can take a closer look?
     
  16. xinuxano

    xinuxano

    Joined:
    Feb 28, 2018
    Posts:
    33
    Sorry so much!! my answer has been too short. I will try to explain myself better.

    I have created an action in XRHMD Input Actions called Presence. This Input Action, from Action Type equal to Button. In its properties, the Binding is <XRHMD>/userPresence

    For the call to the script I use Player Input. With Behavior equal to Send Messages.

    Finally, the script where where the event is expected to arrive (but nothing arrives), is very simple.

    Code (CSharp):
    1. public void OnPresence(){
    2.    Debug.Log("Hi");
    3. }
     
    Last edited: Jun 2, 2021
  17. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    I am just familiar with the player input with bahavior script. I dont know whether the action is being enabled, or how it is listening for change, etc. Likely the issue lies somewhere in that logic as binding directly the action seems to work. I would need to see the project to be able to debug any further.
     
  18. squishysoul

    squishysoul

    Joined:
    Jan 8, 2021
    Posts:
    2
    Okey so I'm testing this on index, action set to userPresence [XR HMD], code in awake goes like above

    Code (CSharp):
    1. HeadsetOnActionReference.action.started += (ctx) => Debug.Log($"UserPresence: started");
    2.         HeadsetOnActionReference.action.performed += (ctx) => Debug.Log($"UserPresence: performed");
    3.         HeadsetOnActionReference.action.canceled += (ctx) => Debug.Log($"UserPresence: canceled");
    And 'started' and 'performed' are fired at the very begging, even though my headset is resting on desk. 'canceled' doesnt fire itself at all, but if I click on console window in Unity, all three fire at once, every following clicking game and console window fire these event again. It seems it doesnt react on actual headsed mounted or not. Am I reading this action incorrectly, is it in fact application focus, or am I doing something wrong?
    I have also tried reading value, changing value type, tried most of actions I didnt know meaning for, and I just cant get it to work.
    Im using unity 2020.3.17f1 with XR Plugin Management 4.0.7 and XR Interaction Toolkit 1.0.0-pre.5
     
  19. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467

    Is it possible for you to report a bug with `Help -> Report a Bug` with a small sample project that demonstrates this? If you can please post the issue # here so we can look into it faster.
     
  20. squishysoul

    squishysoul

    Joined:
    Jan 8, 2021
    Posts:
    2
    Sure, issue number 1365881
     
  21. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Great, we will take a look.
     
    squishysoul likes this.
  22. aquadragon3d

    aquadragon3d

    Unity Technologies

    Joined:
    Sep 20, 2021
    Posts:
    11
    Hi,
    After some investigation, SteamVR fixed this and the fix will be coming out in a future beta.
     
    xinuxano likes this.
  23. ntclark

    ntclark

    Joined:
    Nov 10, 2020
    Posts:
    10
    I too have this exact problem, we are required to know when the user has the headset on or off. It is absolutely critical to our functionality.

    I'm very confused by the context of these answers however.

    The OP was, I thought, referring to OpenXR as he mentions that they are using OpenXR 1.1.1.

    However, the last entry above mine refers to SteamVR !?!? This is the source of my confusion.

    We are very keen on replacing SteamVR completely and had hoped that OpenXR was the path for that

    Anyway, from that post and the answers here, I learned about input actions and have created what I believed SHOULD work, though it doesn't.

    Tracking it down, using the Input Debugger, I can see that the headset "userpresence" value is 1 at ALL times whether I have my finger over the sensor or not.

    Further, I create a basic unity project with absolutely nothing in it but a cube, and again, the input debugger shows userpresence = 1 at all times.

    Tried just now with Unity 2021.2.0f1, but in general I have been using 2020.3.17f1

    Also, Unity OpenXR 1.2.8 as well as 1.1.1

    So, have I misunderstood and SteamVR IS somehow behind the scenes in all the posts here that have shown success using input actions ?

    Or am I missing something fundamental ??

    Thanks for any help

    Frankly, if I could get raw access to the hardware, or find the tools to do that, or to do that with the OpenXR reference implementation, I'd do it, but I can't find any info on that either :(
     
  24. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467

    I think you may be confusing the SteamVR OpenXR runtime with the Steam VR OpenVR package. The SteamVR OpenXR runtime works with the OpenXR plugin. In this case the SteamVR runtime has a bug that causes the `UserPresence` value to be incorrect, but it works correctly with other runtimes such as the `Oculus` and `Windows Mixed Reality` runtimes.
     
  25. ntclark

    ntclark

    Joined:
    Nov 10, 2020
    Posts:
    10
    Thanks for the quick reply !!

    My OpenXR runtime is set to the Windows Mixed Reality runtime in the registry and when it's not, the WMR portal prompts for the "fix", which I haven't seen in a long while.

    This unity system is a port from one that WAS using SteamVR, I assume by "Steam VR OpenVR package" you are referring to that distributed with the following package or similar: com.valvesoftware.unity.openvr-1.1.4 ?

    In fact, Steam and SteamVR are both completely removed from my computer, there is nothing left of them (which was the point :) )

    Maybe I've got some invalid configuration in play here, but I can say with 100% confidence that everything is working perfectly as far as unity rendering to the headset and as far as I can tell, every other aspect of the technology, *except* this one minor thing !?!?

    I actually raised the same issue on reddit 4 months ago and for the life of me at the time I *thought* it was working correctly for at least a couple of weeks (like I say, this is critical functionality, I would not have continued with OpenXR if this part wasn't working up front !), but one day, out of the blue the functionality went belly up - I looked at great length for computer/usb problems but never found the solution. Instead I spoof the functionality by implementing an input key.

    It was only until today that I discovered the Input Debugger, and these input actions (where before I was trying to use TryGetFeature(UserPresence) <- or something similar)

    Anyway, thanks, I appreciate the help
     
  26. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Yes the com.valvesoftware.unity.openvr-* is the Steam OpenVR package.

    What headset are you using? We can double check to make sure userpresence is working on the WMR runtime with that headset.
     
  27. ntclark

    ntclark

    Joined:
    Nov 10, 2020
    Posts:
    10
    Thanks - I am using a Samsung odyssey. WMR Portal reports it as "Samsung Windows Mixed Reality 800ZBA", and this also happens with an HP Reverb (the headset is NOT G2)

    I have a Vive on it's way, we'll see what that does, and I DO have an oculus headset, but, IIRC, I can't use the Unity OpenXR with it, have to use the Oculus OpenXR plugin, anyway, it's a PIA to install that with all it's software. In any case, our target audience is WMR compatible headsets.

    Thanks
     
    Last edited: Oct 27, 2021
  28. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    I happen to also have a Sumsung odyssey here and tried this myself and did see that `UserPresence` was not changing when I took the headset on/off. I could see the sensor light on the headset change though. I opened a discussion with Microsoft about this as this information comes from the Runtime. I also noticed that when the headset is sitting on my desk it is still tracking in the Mixed Reality Portal as well, which may be related.
     
    CBHM likes this.
  29. ntclark

    ntclark

    Joined:
    Nov 10, 2020
    Posts:
    10
    Thank you very much for following through !

    That is very interesting that the info comes from the runtime. I vaguely remember that this particular problem started, I believe, about the time of an update or reinstall of the mixed reality portal, which likely involved some update to the runtime. In fact, the build date on the runtime is July 13 !

    Thanks, let me know if you hear anything
     
  30. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    The current status of this is `UserPresence` is not something that is exposed by OpenXR. We tried linking it to the Focus state of the Runtime but it looks like WMR does not drop out of focus state when you take the headset off. The current proposed solution is to push forward an extension to expose this information and that discussion has been opened with the working group. This all of course takes time, so unfortunately I wouldnt expect a resolution in the immediate future. We will continue to work on this issue with the working group though.
     
  31. ntclark

    ntclark

    Joined:
    Nov 10, 2020
    Posts:
    10
    Hi @the_real_apoxol I found some useful information the other day - and I did post it here, but a little while later I came back and deleted the post because I wasn't really sure what I found was correct.

    But here it is anyway - at this point, with some tweaking, User Presence IS working for my needs.

    First, what I discovered was, when you use Unity OpenXR - at some point you get diagnostics about some conflict between the new input system and the legacy input system. I can't recall exactly what that diagnostic is but it occurs in com.unity.ugui@1.0.0\Runtime\UI\MultipleDisplayUtilities.cs - line 40.

    The common "fix" for getting that diagnostic message is to switch the "Active Input System" to "Both" in player settings.

    It was upon changing that setting to "Both" when, in my case, User presence functionality went belly up. I noticed this by starting from scratch and proceeding piece by piece until I got that failure.

    If I put a try/catch block around that code in ugui - I can continue working on my project and headset detection IS working.

    I tell you this in hopes that it is additional information you can use. I probably should have kept it in the post yesterday but I got confused at some point and thought it might be incorrect so I deleted the post.

    I sincerely appreciate that you've kept this issue alive and have taken steps to solve it, I assume what you've related in your last post is the more "correct" way to fix it - but in any case, perhaps this additional information may help
     
    the_real_apoxol likes this.
  32. ntclark

    ntclark

    Joined:
    Nov 10, 2020
    Posts:
    10
    Again - I should probably remove my last post regarding the solution. In any case, now I recall why I was confused and removed the previous post the other day. Sincerely, I apologize if this back and forth is causing issues.

    The bottom line reason for how User presence detection is working is that I completely removed the Unity OpenXR plugin and am using the Windows Mixed Reality OpenXR plugin version 1.1.2 solely - that is, with nothing else

    That works great other than the scene is very dim in the headset, I am desparately trying to find out why
     
  33. rtartakovsky

    rtartakovsky

    Joined:
    Jan 18, 2022
    Posts:
    7
    Have there been any updates on this front? The HP Reverb G2 still does not expose an accurate userPresence even while using the latest OpenXR and Input System plugins. Is there an extension actively in the works to enable Unity to read userPresence from whichever OpenXR runtime the headset is running on (SteamVR or Windows Mixed Reality)? If so, is there a timeframe in which a preview could be released?
     
    CBHM likes this.
  34. Max_Aigner

    Max_Aigner

    Joined:
    May 9, 2017
    Posts:
    42
    On my Quest 2 (connected via Oculus Link) I get the same weird behaviour, therefore it seems that it might still be broken somehow.. Or we use it in a wrong way (?)

    Or does userPresence work on someones's quest 2 at all?

    Code (CSharp):
    1. playerInputActions = new PlayerInputActions();
    2.         playerInputActions.Player.Enable();
    3.         playerInputActions.Player.HMDMount.started += HMDMount_performed;
    4.         playerInputActions.Player.HMDMount.canceled += HMDMount_canceled;
    5.     }
    6.  
    7.     private void HMDMount_canceled(InputAction.CallbackContext obj)
    8.     {
    9.         Debug.Log("canceled hmd " );
    10.     }
    11.  
    12.     private void HMDMount_performed(InputAction.CallbackContext obj)
    13.     {
    14.         Debug.Log("started hmd " );
    15.     }
    The weird thing about that is, that I can see the stat in the Input debugger / OculusQuest Device and it works perfectly well.
    upload_2022-4-21_16-15-6.png

    Actually as soon as the Oculus Quest gets started, I get the "canceled" Event of the userpresence and after that I don't get any more events no matter how often I put the headset on or off my head.
    upload_2022-4-21_16-16-18.png


    One more thing that does not make sense is, that in the "Input Debug" Window it pretends to use "OculusQuest/istracked" instead of the action "OculusQuest/userPresence". Maybe that is the origin of this bug.
    upload_2022-4-21_16-20-51.png

    I would have expected it to be userPresence just like I have set it up in my actionmap:
    upload_2022-4-21_16-21-13.png

    So obviously userPresence got confused with isTracked by Unity or whom ever..
     
    Last edited: Apr 21, 2022
  35. Max_Aigner

    Max_Aigner

    Joined:
    May 9, 2017
    Posts:
    42
    So I solved that Issue by using this little static class here, that I created in order to get the userPresence of my HMD:

    Just add this class somewhere in your Scripts folder and use it like "XRDevice.IsHMDMounted();"

    Code (CSharp):
    1.  
    2. using UnityEngine.XR;
    3.  
    4. public class XRDevice
    5. {
    6.     private static InputDevice headDevice;
    7.     public XRDevice() {
    8.         if (headDevice == null)
    9.         {
    10.             headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
    11.         }
    12.     }
    13.  
    14.     /// <summary>
    15.     /// returns true if the HMD is mounted on the users head. Returns false if the current headset does not support this feature or if the HMD is not mounted.
    16.     /// </summary>
    17.     /// <returns></returns>
    18.     public static bool IsHMDMounted()
    19.     {
    20.         if(headDevice == null || headDevice.isValid == false)
    21.         {
    22.             headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
    23.         }
    24.         if (headDevice != null)
    25.         {
    26.             bool presenceFeatureSupported = headDevice.TryGetFeatureValue(CommonUsages.userPresence, out bool userPresent);
    27.             if (headDevice.isValid && presenceFeatureSupported)
    28.             {
    29.                 return userPresent;
    30.             }
    31.             else
    32.             {
    33.                 return false;
    34.             }
    35.         } else
    36.         {
    37.             return false;
    38.         }
    39.     }
    40. }
    41.  
     
    spuchals likes this.
  36. rtartakovsky

    rtartakovsky

    Joined:
    Jan 18, 2022
    Posts:
    7
    The prior post works for Quest perfectly well. However, WMR's OpenXR still doesn't correctly report the Reverb G2's user presence forehead sensor through this method OR the Input System. What's really weird is that using the experimental Windows OpenXR via OpenXR Tools for Windows Mixed Reality doesn't work either, but connecting a WMR instance running experimental OpenXR to the SteamVR beta running its own OpenXR via Windows MR for SteamVR works! However, while this convoluted chain of applications works in-editor, it is not only incredibly clunky to set up, but also has severe stability issues leading to immediate OpenXR crashes in built projects upon the initialization of the XR system.

    To be clear, the problem continues to be that the userPresence begins at 0, is set to 1 when the forehead sensor is triggered the first time, but never resets to 0 when it no longer detects proximity.

    The forehead user presence sensor also works using the deprecated Windows MR plugin for Unity, but we can't use that as the Reverb G2 controllers are no longer supported for the Input System, and we'd have to write custom Input Devices ourselves to catch that input, which represents a work cost that is unacceptable for a deprecated package with no guarantee of future stability and which doesn't allow us to use the OpenXR ecosystem.
     
    Last edited: May 9, 2022
  37. martinamenegon

    martinamenegon

    Joined:
    Aug 28, 2014
    Posts:
    31
    hey! not sure this helps but for me worked: https://www.csdn.net/tags/MtTaMgysMTg2MzU4LWJsb2cO0O0O.html
    I used parts of it for a "scene load/ game reset" -> used with OpenXR, Unity 2020.3, Oculus Quest 2

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine.XR;
    6.  
    7.  
    8. public class gameReset : MonoBehaviour
    9. {
    10.     public static bool IsXRDevicePresent()
    11.     {
    12. #if UNITY_2020_1_OR_NEWER
    13.         return XRSettings.isDeviceActive;
    14. #endif
    15.     }
    16.  
    17.     private void Update()
    18.     {
    19.         if (XRSettings.isDeviceActive == false)
    20.         {
    21.             SceneManager.LoadScene(0);
    22.         }
    23.     }
    24. }
     
    xinuxano likes this.
  38. rtartakovsky

    rtartakovsky

    Joined:
    Jan 18, 2022
    Posts:
    7
    Just to update this thread: after extensive testing with OpenXR custom native plugins capturing the state-data and sent events of the runtime, it appears that, for some reason, specifically when using Windows MR's OpenXR runtime and the HP Reverb, Windows MR's OpenXR does not report any XrSessionState change. The expected behavior is a switch from XR_SESSION_STATE_SYNCHRONIZED to XR_SESSION_STATE_FOCUSED, as the Kronos Group's OpenXR spec states. Since SteamVR and Varjo's OpenXR runtimes handle this sort of thing as expected, I can only assume this is an oversight on Microsoft or HP's end.

    Since the UserPresence property gets set from this state information, if there's no switch, there's no accurate UserPresence.
     
    CBHM and Thomas-Mountainborn like this.
  39. Helvest

    Helvest

    Joined:
    Oct 1, 2016
    Posts:
    2
    This bug is killing the company I work for and its VR game project for the arcade, even if I try to rely on movements and the angle of the helmet, mixed with timers and all the other tricks I know or find, it's still very difficult to detect the absence of a player as soon as possible.

    So for the moment I'm stuck with a system that returns a lot of false positives, I won't tell you what it does to the confidence of customers towards VR, it will depress you too much.
     
  40. phileday

    phileday

    Joined:
    Feb 8, 2014
    Posts:
    121
    Hi everyone. I'm also struggling with this and it seems very inconsistent on different devices.

    So here's a bump

    BUMP

    If anyone has worked out how to get the user presence please let us all know.

    All the best

    Philippa

    [Edit]

    So I've not found a way to get the userpresence to work properly, at least on the Quest using Link. but I've found a way to to access another setting that does change when the headset is removed(only on PC, doesn't work on a standalone android build).

    The option is righteyeangularvelocity and can be assigned in the inputcontrollers panel. Once you've done that if you use:
    if (inputActions.Headset.HMDOnHead.inProgress == true)
    {

    }
     
    Last edited: Jan 10, 2023
  41. phileday

    phileday

    Joined:
    Feb 8, 2014
    Posts:
    121
    So I've found a way to test if the Oculus Quest headset is on when using the link cable. The user presence doesn't work which would be the correct way of doing things but what you can do is test the righteyeangularvelocity which drops to 0 when the headset is removed (it's a vector 3). So in my case I added it to the input manager script panel and then in my code I did this:

    if (inputActions.Headset.HMDOnHead.inProgress == true)
    {
    Debug.Log("HandleHMDMounted");
    }
    else
    {
    Debug.Log("HandleHMDUnmounted");
    }

    This seems to work.

    The user presence option is frustratingly broken at the moment, which is a pain as it completely brakes the use of OpenXR if you wish to do cross platform development and need to test of the headsets presence.

    If anyone knows where or who I should nag about this that would be very helpful.

    Philippa
     
  42. phileday

    phileday

    Joined:
    Feb 8, 2014
    Posts:
    121
    Another update for anyone who is interested.

    The userPresence variable doesn't work when using OpenXR through the Oculus desktop software, however it does when using it through Steam. Surprise surprise though, the righteyeangularvelocity detection doesn't work in Steam as the vector3 doesn't set itself to 0 when the headset is removed.
     
  43. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    300
    I have the same problem, after switching to OpenVR from Oculus now the userPresence always return true in the apk.
    there is any solution? (to keep openvr and use userpresence or just read the sensor on the headset)
     
  44. phileday

    phileday

    Joined:
    Feb 8, 2014
    Posts:
    121
    @Ikaro88 I couldn't find a way to do it with OpenXR but both the Pico and Oculus SDK's (not openxr) work when reading the information. It also seems to work better when the OpenXR client is Steam and not Oculus.

    To be honest it just seems broken in OpenXR at the moment and if you need to access the proximity sensor, currently the only option you have is to use the headsets SDK you're building for and not there OpenXR support.
     
  45. Aldeminor

    Aldeminor

    Joined:
    May 3, 2014
    Posts:
    18
    Issue: userPresence.cancelled event is not fired properly
    Setup: Unity Editor + Quest 2 via Cable Link
    Unity version: 2021.3.17
    Relevant packages: OpenXR@1.6.0, Input System@1.4.4

    Steps:
    1. Create script:
    Code (CSharp):
    1. public class XRHeadsetDetector : MonoBehaviour
    2.     {
    3.         public InputAction UserPresence;
    4.  
    5.         private void Start()
    6.         {
    7.             UserPresence.started += x => Debug.Log("Headset is on");
    8.             UserPresence.canceled += x => Debug.Log("Headset is off");
    9.         }
    10.  
    11.         private void OnEnable()
    12.         {
    13.             UserPresence.Enable();
    14.         }
    15.  
    16.         private void OnDisable()
    17.         {
    18.             UserPresence.Disable();
    19.         }
    20.     }
    2. Add script instance to the scene and run Play mode.
    3. Set Action as Button and bind to XR HMD/userPresence
    4. Put the headset on and off.

    What expected: both events are fired properly when headset is on and off.
    What happens: 'started' event is fired properly, but 'cancelled' event is fired not when the headset is removed, but when it is worn on again, right before next 'started' event. Hence there is no way to properly use 'userPresent' feature to detect when the headset is removed.
     
    Last edited: Feb 13, 2023
    Devilkaran likes this.
  46. JuanGuzmanH

    JuanGuzmanH

    Joined:
    Feb 8, 2018
    Posts:
    74
    I'm a huge fan of Unity OpenXR since the first preview package, but I found out that every time I start working on a VR project, I have always the hope of using just unity OpenXR API for production, but at the end, there is always a reason to use the native APIs and discard Unity OpenXR. Sometimes the reason was handtracking, other were a bug, sometimes were a missing feature, ...

    I know things are complex and specially, the challenge to cover every single device and brand is really a complex puzzle that Unity's team is trying to solve for us. I really appreciate.

    I have the feeling this package is really close to be usable in production but there are still key features, like this user presence, that sadly turns this package in to something to play with and experiment but not to use for commercial productions.
     
    Aldeminor likes this.
  47. tomascalinaocorrea

    tomascalinaocorrea

    Joined:
    Mar 9, 2019
    Posts:
    2
    Hi all! Hopping on this thread too as Im running into a similar issue.

    I'm looking to create a script that essentially reboots the experience every time the headset is taken off and put on again. Similar to how VR is used in museums, I need this experience to restart on its own every time a new person puts on the headset.

    Im using the script below in conjunction with the new input system and am running on a Quest Pro. The odd thing is that the script works totally fine when playtesting in Unity, but once I build and deploy the app to my Quest pro it no longer works. This has made things rather difficult as I cant rely on playtesting in Unity to test any changes to the script. Is this a bug? or am I missing something. Any help would be very appreciated. Thanks!


    Code (CSharp):
    1. public class rebootXP : MonoBehaviour
    2. {
    3.     [SerializeField] private InputActionReference Returnhomeactionreference;
    4.    
    5.     // Start is called before the first frame update
    6.     void Start()
    7.     {
    8.         Returnhomeactionreference.action.started += Action_performed;
    9.         Returnhomeactionreference.action.canceled += Action_canceled;
    10.     }
    11.     private void Action_performed(InputAction.CallbackContext obj)
    12.     {
    13.         Debug.Log("headset put on");
    14.     }
    15.  
    16.     private void Action_canceled (InputAction.CallbackContext obj)
    17.     {
    18.         Debug.Log("headset taken off");
    19.         SceneManager.LoadScene(0);
    20.     }
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.         Returnhomeactionreference.action.canceled += Action_canceled;
    25.     }
    26. }
     
  48. Devilkaran

    Devilkaran

    Joined:
    Oct 21, 2020
    Posts:
    1
    @Aldeminor I have also the same Issue ,Did you Get any solution For this .Since it was posted few months back.
    @the_real_apoxol can u please also suggest anything
    upload_2023-6-8_8-27-56.png
     
  49. Aldeminor

    Aldeminor

    Joined:
    May 3, 2014
    Posts:
    18
    @Devilkaran

    I just abandoned OpenXR and moved to OculusXR package along with Meta Quest Inegration asset, since we're targeting Quest 2 device only at this stage of the product development. I hope by the time we will scale to support other devices there will be some progress with OpenXR issues.
     
  50. guillaume_hf

    guillaume_hf

    Joined:
    Jun 1, 2021
    Posts:
    3
    Hi,
    on my side i implemented an OpenXR feature that use the OnSessionBegin and OnSessionEnd to detect the mount/unmount.
    this is working great when i run the app in unity editor through oculus link, but it's not working in builds... any idea how i could get this to work in builds ?