XRDevice.isPresent with XRManagement on Quest

Hey,

It seems like XRDevice.isPresent always returns false on 2019.3.0f6 with the new XR Management system on Oculus Quest. Is that expected?

4 Likes

Please report a bug.

Submitted a bug report. Case: 1215467

Thanks for the advice @Claytonious

2 Likes

Thank you for doing that, but don’t link to your bug reports on Fogbugz - that exposes all of your bug reports to the public, including future ones where you might attach some files or links or info that you don’t want to share with the world. Just post the case number itself (in this case, 1215467).

But thanks again, let’s hope it gets fixed now!

1 Like

@Solovykh
XR Management goes through new APIs.
We have a new Input Features API: Unity - Manual: Unity XR Input
You can get the HMD Input Device, and then call InputDevice.TryGetFeatureValue, with the CommonUsage of UserPresence.

User presence is a boolean. I apologize, this should (and will) be better documented.

1 Like

I was under the impression that CommonUsage.userPresence is a replacement for XRDevice.userPresence which tells me if the user is wearing the headset or not. However, XRDevice.isPresent told me if an HMD was connected or not. Is there anything like that with the InputDevice API?

Oh right, I read that too fast.
That should be even easier (in pseudocode written in this chat bar):

List devices = new List();
InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);
bool isPresent = devices.Count > 0;

If a head mounted device is connected, then the device is present.

2 Likes

So, what … the API call XRDevice.isPresent … is now obsolete, and shouldn’t be used at all? If so, shouldn’t that be documented???

2 Likes

This still seems to be broken or undocumented behaviour. @StayTalm_Unity

2 Likes

Hey @JurjenBiewenga

I’m currently looking into this; I’m updating the documentation and API to reflect the appropriate approach as described in this thread.

I’ll update this thread once it’s live.

6 Likes

Please note that the current ā€œundocumentedā€ situation is downright dangerous.

I just spent two full days debugging total weirdness of one of our applications, and it turns out that with XRManagement active, XRDevice.refreshRate returns 0, while with ā€œLegacy VRā€ it returns 72. Case 1240243

Also @ash_at_unity3d it doesn’t seem like refresh rate is part of the new xr_input API, or is it just not documented? How do I get the device refresh rate in XR Management? This is important to get frame-perfect physics, smooth animations, …

3 Likes

Are there any Updates on this. I want to detect if a VR-Headset is connected.
On unity 2019.4.9f1 i have a WindowsMR Headset connected but both

List<InputDevice> devices = new List<InputDevice>();
InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);
bool isPresent = devices.Count > 0;

and

XRDevice.isPresent

is always false.

XRDevice.isPresent is still not marked as deprecated in Unity, so it took me an hour to find this. Are you intending to update.

Also, I’d just like to voice some concern here. The massive part of the idea of Unity is to be simple for users.However according to the docs, the need to call XRDevice.isPresent has been replaced with the need to write the code:

    public static bool isPresent()
    {
        var xrDisplaySubsystems = new List<XRDisplaySubsystem>();
        SubsystemManager.GetInstances<XRDisplaySubsystem>(xrDisplaySubsystems);
        foreach (var xrDisplay in xrDisplaySubsystems)
        {
            if (xrDisplay.running)
            {
                return true;
            }
        }
        return false;
    }

Not to mention the fact that the whole concept of sub systems is totally undocumented.

Does this not seem like a step backwards?

5 Likes

XR on unity is a mess!

1 Like

With Oculus Quest 2 (Oculus Link), it’s the opposite for me. it’s always true even when i put down the headset

I do not understand.
I make a new Project using the VR default Template
My VR device (Samsung Odyssey) is working fine with Unity 2019.4.18 LTS.
But

UnityEngine.XR.XRDevice.isPresent

is always ā€œfalseā€ as if there is no device.

Working in Unity 2020.1.11f1 the following code works to detect user presence on the Oculus Rift S, but always returns false on Quest 2:

if (!_headset.isValid) _headset = InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);
_headset.TryGetFeatureValue(CommonUsages.userPresence, out bool present);

As far as the new XR api goes, I’m quite happy with this approach. But the code presented in earlier posts by @StayTalm_Unity and @hrgchris would not be appropriate to be called every frame as it involves instantiating a list of devices. Is there any other efficient and reliable way to check for user presence?

1 Like

That usage should work on the Quest 2, I’ll ask around internally why user presence isn’t supported.

If you want to just check that a device exists you can get the current list of devices on startup, and then register to the onDeviceConnected callback: https://docs.unity3d.com/ScriptReference/XR.InputDevices-deviceConnected.html
This will notify you of any new devices so you can assume that if there was no HMD on startup, and no callback with an HMD Input Device, there is still no HMD connected. The HMD should always be connected on first frame (Depending on platform it can sometimes be before Awake, sometimes it takes the first Update), because it is the device running the app, but the above is a good practice for ā€˜Get All, then Notify of changes’ pattern.

Thanks for the reply. I simply want to pause the game while the user isn’t wearing the headset. So, onDeviceConnected isn’t really useful, unfortunately.

Yeah, it sounds like User Presence is definitely what you need.
A few questions:
Have you filed a bug on it? Please do so, and sometimes it can get prioritized better than me nagging a team member.
With Link cable or standalone? Or Both?
When you say it’s returning false, is TryGetFeatureValue returning false, or is present false after calling that function?
The former means the feature doesn’t exist on the device, the latter means the user is not present.