As the title says, I'm trying to enable/disable VR between different applications, and I need to do it as many times as I want. I'm using Unity 2017.4 and SteamVR 2.0.1. I'm trying to do it with two different scenes of the same project (testing one in the editor, and launching the other as .exe).
This solution is not working, since apparently Actions and Poses are not handled correctly when VR is stopped with XRSettings.enabled = false.
Did anyone experienced the same behaviour?
I tried to find a workaround:
1) Disabling/enabling also Player and Hands
...
// ** ENABLE VR **
if (enable)
{
print("Enabling VR ...");
XRSettings.LoadDeviceByName("OpenVR");
yield return null;
print("Loaded device: " + XRSettings.loadedDeviceName);
XRSettings.enabled = enable;
EnablePlayerAndHands(true);
}
// ** DISABLE VR **
else
{
print("Disabling VR ...");
EnablePlayerAndHands(false);
XRSettings.LoadDeviceByName("");
yield return null;
print("Loaded device: " + XRSettings.loadedDeviceName);
XRSettings.enabled = false;
}
...
2) Added these lines in the SteamVR.cs file:
private void Dispose(bool disposing)
{
...
// added code
SteamVR_Input.initialized = false;
SteamVR_Behaviour.instance = null;
}
(In order to make it work, I had to add a public setter for the SteamVR_Behaviour.instance property).
3) In SteamVR_Behaviour, I added a check inside Update(), LateUpdate() and FixedUpdate():
if (_instance != null) ... // do update
These modifications won't fix the problems actually, because I still have some exceptions when I enable back VR, for example:
GetPoseActionData error (/actions/default/in/SkeletonLeftHand): InvalidHandle handle: 1152990670760182193
UnityEngine.Debug:LogError(Object)
Valve.VR.SteamVR_Action_Pose:UpdateValue(SteamVR_Input_Sources, Boolean) (at Assets/SteamVR/Input/SteamVR_Action_Pose.cs:96)
Valve.VR.SteamVR_Action_Skeleton:UpdateValue(SteamVR_Input_Sources, Boolean) (at Assets/SteamVR/Input/SteamVR_Action_Skeleton.cs:75)
Valve.VR.SteamVR_Input:UpdateSkeletonActions(SteamVR_Input_Sources, Boolean) (at Assets/SteamVR/Input/SteamVR_Input.cs:487)
Valve.VR.SteamVR_Input:UpdateSkeletonActions(Boolean) (at Assets/SteamVR/Input/SteamVR_Input.cs:462)
Valve.VR.SteamVR_Input:LateUpdate() (at Assets/SteamVR/Input/SteamVR_Input.cs:352)
Valve.VR.SteamVR_Behaviour:LateUpdate() (at Assets/SteamVR/Scripts/SteamVR_Behaviour.cs:224)
...but they are raised just a few times and then they stop. It could be due to some bad timing. Btw, I put an Interactable gameobject inside the empty scene just to test if I could still interact with it after disabling/enabling, and it seems that I can.
Still, I would expect some easier and cleaner method to achieve my goal. Am I missing something obvious or is it a bug from SteamVR newest version?
Thanks in advance for any help.