- Home /
Enabling VR at runtime does not enable VR controllers
When we load VR at runtime, using code similar to the documentation (https://docs.unity3d.com/ScriptReference/XR.XRSettings.LoadDeviceByName.html), the VR headset works but the VR controllers don't get enabled.
We're using the default SteamVR CameraRig prefab.
It does work when we load VR at the start, without code, by only having 'OpenVR' in the Project Settings -> Player -> XR Settings.
It breaks when we add 'None' to that list above 'OpenVR'. It then starts without VR, then we call XRSettings.LoadDeviceByName and XRSettings.enabled. Again, the camera then works fine, but no controllers.
Manually enabling the controllers does not work (they get an invalid ID). Calling SteamVR_ControllerManager.Refresh() or SteamVR_ControllerManager.UpdateTargets() also does not fix it.
Any tips?
Answer by eatbuckshot · Aug 01, 2018 at 04:59 AM
I have the same issue, this has worked at least prior to Unity 2018.x.x I would load with "None, OpenVR, Oculus" in the player settings then in code
UnityEngine.XR.XRSettings.LoadDeviceByName(new string[] { "OpenVR", "Oculus", "None" });
yield return null;
UnityEngine.XR.XRSettings.enabled = true;
i believe it may even cause unity to crash in a standalone. and the editor log would spam
Assertion failed on expression: 'IsMatrixValid(matrix)'
Screen position out of view frustum (screen pos 0.000000, 0.000000, 1.000000) (Camera rect 0 0 512 531)
Screen position out of view frustum (screen pos 512.000000, 0.000000, 1.000000) (Camera rect 0 0 512 531)
even calling SteamVR.Enabled after words doesn't seem to reinitialize it
This is using the Assetstore version of SteamVR (SteamVR plugin for UNITY v1.2.3)
From some research, I read that the issue has to do with having the scripts on the CameraRig prefab run before VR is enabled. The workaround is to make sure they don't exist before VR is set to enabled. This could be done by instantiating a the CameraRig prefab only after s$$anonymous$$mvr and XR gets enabled. Which likely needs at least a frame to be finished, so a 2nd yield return null after enabling i believe..
Your answer
Follow this Question
Related Questions
Mixed Reality (Odyssey) controllers not tracking with SteamVR interaction system! 0 Answers
Show Open File panel in Unity SteamVR application 0 Answers
Editor Crashes When Switching from VR to Standalone 0 Answers
Camera and objects in steamVR plugin 0 Answers
,Cloned TeleportArea not working 1 Answer