question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enabling/disabling VR with SteamVR v.2

See original GitHub issue

Hi everybody!

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 working with Unity 2017.4 and SteamVR 2.0.1 (I also tried with 2.2, same behaviour).

There is a simple solution for this:

IEnumerator SwitchOutOfVr() {
        XRSettings.LoadDeviceByName(""); // Empty string loads the "None" device.
        // Wait one frame!
        yield return null;
        XRSettings.enabled = false;
}

but I got nasty exceptions since Actions and Poses don’t seem to be handled correctly after disabling VR; instead, the update functions are still called:

NullReferenceException: Object reference not set to an instance of an object Valve.VR.SteamVR_Action_Pose_Source.UpdateValue (Boolean skipStateAndEventUpdates) (at Assets/SteamVR/Input/SteamVR_Action_Pose.cs:571) Valve.VR.SteamVR_Action_Skeleton_Source.UpdateValue (Boolean skipStateAndEventUpdates) (at Assets/SteamVR/Input/SteamVR_Action_Skeleton.cs:904) Valve.VR.SteamVR_Action_Skeleton.UpdateValue (Boolean skipStateAndEventUpdates) (at Assets/SteamVR/Input/SteamVR_Action_Skeleton.cs:65) Valve.VR.SteamVR_Input.UpdateSkeletonActions (Boolean skipSendingEvents) (at Assets/SteamVR/Input/SteamVR_Input.cs:355) Valve.VR.SteamVR_Input.LateUpdate () (at Assets/SteamVR/Input/SteamVR_Input.cs:269) Valve.VR.SteamVR_Behaviour.LateUpdate () (at Assets/SteamVR/Scripts/SteamVR_Behaviour.cs:219)

I’d like to know if I’m doing something wrong or it’s something that will be fixed. Thanks in advance for any hint.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:11

github_iconTop GitHub Comments

7reactions
zitecommented, Feb 8, 2019

Yeah, being able to disable steamvr seems like a reasonable request. I’ll add it to the feature request list.

3reactions
JorgeZubogcommented, Dec 4, 2019

Hello, I have exactly the same problem, I need enabling/disabling VR as many times as the player wants, however in the second time I get the same errors and in the application build I lose the controllers tracking. I’m working with the player prefab, I have the current plugin version 2.5.0 (sdk 1.8.19) and SteamVR 1.8.20 version.

I’ll be very glad with any help 😃

This is my code:

IEnumerator EnableVR(bool enable)
    {
        // ** ENABLE VR **
        if (enable)
        {
            mainCamera.SetActive(false);

            if (string.Compare(XRSettings.loadedDeviceName, "OpenVR", true) != 0)
            {
                XRSettings.LoadDeviceByName("OpenVR");
                yield return null;
            }
            XRSettings.enabled = true;

            yield return null;

            player.SetActive(true);

            print("Enabling VR ...");
            SteamVR.Initialize(true);
        }
        // ** DISABLE VR **
        else
        {
            player.SetActive(false);

            print("Disabling VR ...");
            Destroy(FindObjectOfType<SteamVR_Behaviour>());
            XRSettings.LoadDeviceByName(""); // still needed to release the Vive
            yield return null;

            XRSettings.enabled = false;
            yield return new WaitForSeconds(2);

            mainCamera.SetActive(true);
        }


    }

This are the errors:

NullReferenceException: Object reference not set to an instance of an object
Valve.VR.SteamVR_Action_Pose_Source.UpdateValue (System.Boolean skipStateAndEventUpdates) (at Assets/SteamVR/Input/SteamVR_Action_Pose.cs:575)
Valve.VR.SteamVR_Action_Skeleton_Source.UpdateValue (System.Boolean skipStateAndEventUpdates) (at Assets/SteamVR/Input/SteamVR_Action_Skeleton.cs:917)
Valve.VR.SteamVR_Action_Skeleton.UpdateValue (System.Boolean skipStateAndEventUpdates) (at Assets/SteamVR/Input/SteamVR_Action_Skeleton.cs:65)
Valve.VR.SteamVR_Input.UpdateSkeletonActions (System.Boolean skipSendingEvents) (at Assets/SteamVR/Input/SteamVR_Input.cs:355)
Valve.VR.SteamVR_Input.LateUpdate () (at Assets/SteamVR/Input/SteamVR_Input.cs:269)
Valve.VR.SteamVR_Behaviour.LateUpdate () (at Assets/SteamVR/Scripts/SteamVR_Behaviour.cs:230)

NullReferenceException: Object reference not set to an instance of an object
Valve.VR.SteamVR_ActionSet_Manager.UpdateActionStates (System.Boolean force) (at Assets/SteamVR/Input/SteamVR_ActionSet_Manager.cs:57)
Valve.VR.SteamVR_Input.UpdateVisualActions (System.Boolean skipStateAndEventUpdates) (at Assets/SteamVR/Input/SteamVR_Input.cs:315)
Valve.VR.SteamVR_Input.OnPreCull () (at Assets/SteamVR/Input/SteamVR_Input.cs:302)
Valve.VR.SteamVR_Behaviour.PreCull () (at Assets/SteamVR/Scripts/SteamVR_Behaviour.cs:219)
Valve.VR.SteamVR_Behaviour.OnBeforeRender () (at Assets/SteamVR/Scripts/SteamVR_Behaviour.cs:189)
UnityEngine.BeforeRenderHelper.Invoke () (at C:/buildslave/unity/build/Runtime/Export/Graphics/BeforeRenderHelper.cs:92)
UnityEngine.Application.InvokeOnBeforeRender () (at C:/buildslave/unity/build/Runtime/Export/Application/Application.cs:318)


Read more comments on GitHub >

github_iconTop Results From Across the Web

Enabling/disabling VR with SteamVR 2.0.1
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...
Read more >
Disable/Enable VR from code using SteamVR 2.0.1
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...
Read more >
How do I disable SteamVR launching when programs with ...
I have some programs that "Technically" have VR modes and are auto-launching SteamVR every time I open them, even if I am not...
Read more >
Borderlands 2 launch options. Find Game Which You would Lik
To disable the Borderlands 2 launcher, set the following launch option within Steam: Right-click on 'Borderlands 2' under the game Library in Steam...
Read more >
Beat saber soundreplacer. org for rating information Music ...
Features: NEW: In-Game Menu for selecting sound files and enabling/disabling custom sounds. Freerunning is a great fit for VR (provided you have the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found