How to check in script for XR Settings if HMD is present or plugin is actively enabled to load

hey folks i’ve got a situation in a course i’m teaching where myself or my students may be using the Editor both in Standalone Mode and also in VR. the new XR Toolkit and Input system manage the switch off very well which is more convenient than the VRTK method of completely different rig setups. so visually the Editor mode without VR and with VR are pretty close to each other in terms of look and feel in the Game View but there’s still some issues i’d like to tweak visually if the VR HMD and controllers are present or if not it falls back to standard Desktop layout and disables the controller objects.

anyway, how do you check if the HMD and controllers are present or not via a simple flag at startup in a script? alternately is there a way to check the XR plugin settings from a script to see if any are active? i’m in Unity 2020.1 BTW. thanks in advance!

1 Like

You can query devices based on their characteristics and base you logic on the output:
Unity - Scripting API: XR.InputDevices.GetDevicesWithCharacteristics (unity3d.com)

You can’t really check if the HMD is present without starting VR, but you can use the MockHMD to switch between XR and Non-XR more easily than using an actual headset.

About the Mock HMD XR Plugin | MockHMD XR Plugin | 1.1.3-preview.1 (unity3d.com)

If you just want to check if XR is active you can check the XRGeneralSettings.Instance?.Manager?.activeLoader to see if it is non-NULL. If it’s not null, then XR is actively running.

About the XR Plug-in Management package | XR Plugin Management | 3.2.17 (unity3d.com)

1 Like

That returns not-null, even with headset is not connected.

Still searching for a way to detect whether to start VR or PC mode… (if no headset is connected)
In steamvr its pretty much automatic, you get one error that hmd not found, and you are in PC mode.