Search Unity

Question Detect headset removed

Discussion in 'VR' started by yessaad, Feb 8, 2021.

  1. yessaad

    yessaad

    Joined:
    Jan 14, 2021
    Posts:
    1
    Hi all,

    I'm a newbie developer and currently work for a museum.
    I want to control a 360 degree video without using the controllers.
    I am using the "isuserpresent" function to play / pause / stop the video. Everything works fine in the runtime (oculus Link) but when I build it doesn't.

    Does anyone have any idea where the problem is ?

    I work with Unity 2019.4 + Bolt + Oculus integration 23.1
     
  2. Tanya_Li

    Tanya_Li

    Unity Technologies

    Joined:
    Jun 29, 2020
    Posts:
    105
    Hey,

    You could try using CommonUsages.userPresence. https://docs.unity3d.com/ScriptReference/XR.CommonUsages-userPresence.html

    Example as below:
    Code (CSharp):
    1.        
    2. InputDevice headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
    3. if (headDevice.isValid)
    4. {
    5.     bool userPresent = false;
    6.     bool presenceFeatureSupported = headDevice.TryGetFeatureValue(CommonUsages.userPresence, out userPresent);
    7.     Debug.Log("presence feature supported " + presenceFeatureSupported + " userPresent is " + userPresent);
    8. }
     
  3. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    300
    this works fine but not work with openXR on quest 2 (works on editor but NOT on build)
    Any way to let it work with OpenXR?
     
    d1favero likes this.
  4. AndreasWang

    AndreasWang

    Joined:
    Jul 31, 2019
    Posts:
    23
    You could make an OpenXR feature and override OnSessionStateChange() to check for user presence. The input parameters map to this enum, and you could consider XR_SESSION_STATE_FOCUSED as a state where the user is present
     
    npatch likes this.
  5. amogha_unity

    amogha_unity

    Joined:
    May 11, 2023
    Posts:
    1
    Hello,
    I am actually working on a Pico headset and found out PXR_SDK does have the provision where we can detect if the headset is removed or not.
    Can someone suggest me what would be the best option for me to detect if the headset is removed or not in the android build.

    Unity version:2021.3.21

    Thanks
     
  6. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
    Just tried this. Works nicely.

    The runtime basically cycles through XR_SESSION_STATE_IDLE all the way to XR_SESSION_STATE_FOCUSED and back(obviously in reverse order) when someone puts the headset on and takes it off.

    Seems like a perfect workaround at least in-editor. Are there any pitfalls to this method?!
     
  7. AndreasWang

    AndreasWang

    Joined:
    Jul 31, 2019
    Posts:
    23
    The main things I can think of is:
    1. You'll generally be moving between XR_SESSION_STATE_FOCUSED and XR_SESSION_STATE_VISIBLE whenever you press the oculus button to bring up the system menu (as far as I can remember!), so if that matters in your case you might want to take it into account.
    2. If you are using SteamVR as your OpenXR runtime, they used to keep you in XR_SESSION_STATE_FOCUSED state, regardless of whether the headset had presence or not. It's been a while ago since I tested this though so it might be different these days.
     
    npatch likes this.
  8. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
    Ah nice. I have mapped through testing other states, but hadn't checked to see what happens with the system menu.
    Not using SteamVR, Meta's for Windows.
     
  9. djhatvr

    djhatvr

    Joined:
    Sep 22, 2019
    Posts:
    53
  10. Nick-Nexefy

    Nick-Nexefy

    Joined:
    Mar 20, 2019
    Posts:
    8
    I've been my own tests checking user presence and it seems that different headsets seem to behave differently.
    With the Vive Pro headsets, using the method above to check presence and polling each frame does appear to work.
    Code (CSharp):
    1. headDevice.TryGetFeatureValue(CommonUsages.userPresence, out userPresent)
    However when using Vive Focus 3 and streaming to the headset via Vive Streaming HUB, it doesn't seem to consistently detect the headset is taken off.
    ----
    In the case of detecting presence as native app on a Focus 3, using this plugin asset from the asset store has worked for me.
    https://assetstore.unity.com/packages/tools/integration/pa-proximity-25685
     
  11. Tanya_Li

    Tanya_Li

    Unity Technologies

    Joined:
    Jun 29, 2020
    Posts:
    105
    AndreasWang, Nick-Nexefy and npatch like this.