Stop and Restart XR Plugin Management

Hi I was following this thread toggle between 2d and Google Cardboard - #20 by lz7cjc

Using Unity 2019.4.26f1 - XR Plugin Management 4.0.7

I want to check for an active headset and let the player decide to use a VR headset or a Desktop Keyboard/Mouse option.

After testing for an active headset, I shutdown XR as I don’t want the VR headset to be active active until they choose it.

I am able to stop XR Plugin Management, I load another scene when they choose VR and I attempt to restart XR and it seems like it restarts but when I go to my quest over PC-Link or Air-Link the Unity App is stuck in a Loading state. The app is playing fine in the editor or in a build, just no joy in the headset

Edit: I do get the following error

Failed to set DeveloperMode on Start.
UnityEngine.Debug:LogError (object)
Unity.XR.Oculus.Development:OverrideDeveloperModeStart () (at Library/PackageCache/com.unity.xr.oculus@1.8.1/Runtime/OculusDevelopment.cs:39)
Unity.XR.Oculus.OculusLoader:Start () (at Library/PackageCache/com.unity.xr.oculus@1.8.1/Runtime/OculusLoader.cs:176)
T5_VR_LobbyMod/<StartXR>d__8:MoveNext () (at Assets/PlatformUpdates/Scripts/T5_VR_LobbyMod.cs:80)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

Any suggestions?

1 Like

Same problem here after updating to 1.10 on the oculus plugin. Have you solved it?

Same!

using
Unity 2020.3.18f1
XR Interaction Toolkit
2.0.0-pre.6

Also updated:
Oculus XR Plugin
Open XR Plugin

Had the same problem with 2022.3. It looks like Unity does not properly getting rid of Oculus’ stuff. So the solution is to check if the XR stuff is enabled, disable it, and then enable it again :smile:

Here is the code:

using System.Collections;
using UnityEngine.XR.Management;

public static class OvrController
{
    public static IEnumerator EnableXRCoroutine()
    {
        // Make sure the XR is disabled and properly disposed. It can happen that there is an activeLoader left
        // from the previous run.
        if(XRGeneralSettings.Instance.Manager.activeLoader || XRGeneralSettings.Instance.Manager.isInitializationComplete)
        {
            DisableXR();
            yield return null;
        }

        // Enable XR
        yield return XRGeneralSettings.Instance.Manager.InitializeLoader();

        if(!XRGeneralSettings.Instance.Manager.activeLoader || !XRGeneralSettings.Instance.Manager.isInitializationComplete)
        {
            // Something went wrong, XR is not enabled
            yield break;
        }

        XRGeneralSettings.Instance.Manager.StartSubsystems();
        yield return null;

        // Not that OVRBody and OVRFaceExpressions components will not enable themselves automatically.
        // You will have to do that manually
        OVRPlugin.StartBodyTracking();
        OVRPlugin.StartFaceTracking();
    }

    public static void DisableXR()
    {
        if(XRGeneralSettings.Instance.Manager.isInitializationComplete)
        {
            OVRPlugin.StopBodyTracking();
            OVRPlugin.StopFaceTracking();

            XRGeneralSettings.Instance.Manager.StopSubsystems();
            XRGeneralSettings.Instance.Manager.DeinitializeLoader();
        }
    }
}
1 Like

Thank you, it worked for me :slight_smile:

Where should I call EnableXRCoroutine? In an Awake method?

I was able to get this script to fix the issue → Dorkbots-UnityUtils/Dorkbots/XR/EnableXR.cs at main · dorkbot/Dorkbots-UnityUtils · GitHub

1 Like

worked like a charm! thank you!!