Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Stop and Restart XR Plugin Management

Discussion in 'VR' started by ibyte, Jul 23, 2021.

  1. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,045
    Hi I was following this thread https://forum.unity.com/threads/toggle-between-2d-and-google-cardboard.902378/#post-5939201

    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

    Code (CSharp):
    1. Failed to set DeveloperMode on Start.
    2. UnityEngine.Debug:LogError (object)
    3. Unity.XR.Oculus.Development:OverrideDeveloperModeStart () (at Library/PackageCache/com.unity.xr.oculus@1.8.1/Runtime/OculusDevelopment.cs:39)
    4. Unity.XR.Oculus.OculusLoader:Start () (at Library/PackageCache/com.unity.xr.oculus@1.8.1/Runtime/OculusLoader.cs:176)
    5. T5_VR_LobbyMod/<StartXR>d__8:MoveNext () (at Assets/PlatformUpdates/Scripts/T5_VR_LobbyMod.cs:80)
    6. UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
    Any suggestions?
     
    Last edited: Jul 23, 2021
    NeolithicJames likes this.
  2. NeolithicJames

    NeolithicJames

    Joined:
    Feb 28, 2018
    Posts:
    3
    Same problem here after updating to 1.10 on the oculus plugin. Have you solved it?
     
  3. DavidZobrist

    DavidZobrist

    Joined:
    Sep 3, 2017
    Posts:
    232
    Same!

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

    Also updated:
    Oculus XR Plugin
    Open XR Plugin
     
  4. antonsem

    antonsem

    Joined:
    Dec 13, 2012
    Posts:
    18
    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 :D

    Here is the code:

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine.XR.Management;
    3.  
    4. public static class OvrController
    5. {
    6.     public static IEnumerator EnableXRCoroutine()
    7.     {
    8.         // Make sure the XR is disabled and properly disposed. It can happen that there is an activeLoader left
    9.         // from the previous run.
    10.         if(XRGeneralSettings.Instance.Manager.activeLoader || XRGeneralSettings.Instance.Manager.isInitializationComplete)
    11.         {
    12.             DisableXR();
    13.             yield return null;
    14.         }
    15.  
    16.         // Enable XR
    17.         yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    18.  
    19.         if(!XRGeneralSettings.Instance.Manager.activeLoader || !XRGeneralSettings.Instance.Manager.isInitializationComplete)
    20.         {
    21.             // Something went wrong, XR is not enabled
    22.             yield break;
    23.         }
    24.  
    25.         XRGeneralSettings.Instance.Manager.StartSubsystems();
    26.         yield return null;
    27.  
    28.         // Not that OVRBody and OVRFaceExpressions components will not enable themselves automatically.
    29.         // You will have to do that manually
    30.         OVRPlugin.StartBodyTracking();
    31.         OVRPlugin.StartFaceTracking();
    32.     }
    33.  
    34.     public static void DisableXR()
    35.     {
    36.         if(XRGeneralSettings.Instance.Manager.isInitializationComplete)
    37.         {
    38.             OVRPlugin.StopBodyTracking();
    39.             OVRPlugin.StopFaceTracking();
    40.  
    41.             XRGeneralSettings.Instance.Manager.StopSubsystems();
    42.             XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    43.         }
    44.     }
    45. }