Search Unity

Enabling/disabling VR with SteamVR 2.0.1

Discussion in 'AR/VR (XR) Discussion' started by ireth_86, Jan 22, 2019.

  1. ireth_86

    ireth_86

    Joined:
    May 18, 2016
    Posts:
    23
    Hello,
    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.

    Using https://forum.unity.com/threads/enable-disable-steamvr-on-focus-gain-loss.510914/ will work, but since SteamVR got updated with Actions and Poses etc., I got nasty exceptions since these things don't seem to be handled correctly after disabling VR.
    I also tried to disable all actions before disabling, but when I want to come back and enable VR back, nothing will actually work.

    Did anyone experience this? How can we fix it?
     
  2. ireth_86

    ireth_86

    Joined:
    May 18, 2016
    Posts:
    23
    Update:

    In order to handle actions and poses when disabling VR, in the Dispose() method of class SteamVR, I added two lines:
    Code (CSharp):
    1. SteamVR_Input.initialized = false;
    2. SteamVR_Behaviour.instance = null;
    (I also had to add a public setter for the SteamVR_Behaviour.instance property).

    Also, in SteamVR_Behaviour, I added a check inside Update, LateUpdate and FixedUpdate:

    Code (CSharp):
    1. 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:

    Code (CSharp):
    1. GetPoseActionData error (/actions/default/in/SkeletonLeftHand): InvalidHandle handle: 1152990670760182193
    2. UnityEngine.Debug:LogError(Object)
    3. Valve.VR.SteamVR_Action_Pose:UpdateValue(SteamVR_Input_Sources, Boolean) (at Assets/SteamVR/Input/SteamVR_Action_Pose.cs:96)
    4. Valve.VR.SteamVR_Action_Skeleton:UpdateValue(SteamVR_Input_Sources, Boolean) (at Assets/SteamVR/Input/SteamVR_Action_Skeleton.cs:75)
    5. Valve.VR.SteamVR_Input:UpdateSkeletonActions(SteamVR_Input_Sources, Boolean) (at Assets/SteamVR/Input/SteamVR_Input.cs:487)
    6. Valve.VR.SteamVR_Input:UpdateSkeletonActions(Boolean) (at Assets/SteamVR/Input/SteamVR_Input.cs:462)
    7. Valve.VR.SteamVR_Input:LateUpdate() (at Assets/SteamVR/Input/SteamVR_Input.cs:352)
    8. 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 object inside the empty scene just to test if I could still interact with it after disabling/enabling, and it seems that I can.
    Also, after disabling and enabling back, I disable/enable also Player and Hands scripts.

    Anyway, I wonder if there is an easier and more correct way to achieve a cleaner result.