My app uses VR SDKs (Project Settings - Player) in this order:
Open VR
None
If I unplug the headset (Lenovo Explorer) and start the app, Unity (2017.3.1f1) prints an error message:
Isn’t the “None” SDK supposed to become active if there’s no headset connected, so you can use your app with or without an HMD? I’m not trying to get tracking to work without the HMD, I just want to use it as a normal, non-VR desktop app too (so without Steam/SteamVR/OpenVR).
How do I make this work? Do I really have to export/give two different versions to the users, one with “Virtual Reality Supported” (Project Settings - Player) ticked, one without it ticked?
Starting the app without an HMD doesn’t produce the error message anymore but now there’s a new problem:
While plugging the headset in opens the “Mixed Reality-Portal”, it doesn’t open SteamVR and if SteamVR isn’t open, Unity apparently also doesn’t recognize the headset as a VR device. This also means that “XRDevice.isPresent” always returns “false” (same thing with “XRSettings.isDeviceActive”) and “XRSettings.loadedDeviceName” of course returns an empty string.
Btw, switching the SDKs, so “OpenVR” is first, starting my app to open SteamVR and then switching back doesn’t work - Unity instantly forgets about the headset again.
Has anyone got any idea/suggestion what I could try to automatically detect an HMD, while still being able to run the app in non-VR mode (without the “Hmd Not Found (108)” message)?
Edit: Even if I force it with “if(!XRDevice.isPresent)” and additionally add “XRSettings.enabled = true”, it doesn’t work. SteamVR starts but the headset only shows the dark gray waiting room. As soon as I move “OpenVR” back to the top of the list, everything’s back to normal in VR mode but then I keep getting the “Hmd not found” error message again.
I contacted support:
“None” doesn’t provide any way of detecting if a headset is connected (as assumed), while the “Hmd Not Found” messages is thrown by OpenVR and can’t be caught/isn’t caught by Unity.
The solution I’m currently using and which is easier (to maintain, imo) than two exporting two different exes with two different folders for basically the same code:
Export with “None” first in the list and “OpenVR” second, then create two batch files (the original exe starts the app without VR) and put them in the folder the exe is in:
Start myapp.exe -vrmode openvr
Start myapp.exe -vrmode none
This starts the app with the chosen mode, as if you’d put it first in the list for the current session.
If the OpenVR version is started without a headset connected there’s still going to be the “Hmd Not Found” error but there’s really nothing I can do about that at the moment.
If oneone has come up with a different solution, please feel free to share.
I have found a solution for my use case - by using SteamVR SDK, which includes a simple check if a VR device is attached: OpenVR.IsHmdPresent() - don’t forget import Valve.VR at the top!
I am also using the CameraRig from SteamVR which includes a camera with decent default VR settings. Alongside this, I have a nearly identical 2nd camera. Depending on if VR is active or not, I change the MainCamera tag of each camera and disable/enable the VR/Non-VR cameras. This seems to work fine with a HTC Vive Pro but I haven’t tested it with other headsets.
Sounds like it could be an issue. My understanding is that there should be a fallback mechanism in place for it to step through the list if the current one fails for any reason. Could you file a bug with a repro project attached and post the number here so we can do an investigation in that behavior?