Search Unity

  1. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Bug ARFoundation not working after loading it programmatically by index

Discussion in 'AR' started by LuisJavierLopez, Sep 1, 2021.

  1. LuisJavierLopez

    LuisJavierLopez

    Joined:
    May 23, 2019
    Posts:
    6
    Unity: 2020.3.14f1

    ARFoundation: 4.1.7 (base project from https://github.com/Unity-Technologies/arfoundation-samples/tree/4.1)

    Reproduced: on Android

    Problem:
    Automatic XR loading for specific XR loaders does not work for ARFoundation.

    How to reproduce

    This is the Unity project: https://manyworlds.synology.me/manyworlds/development/tmp/arfoundation-samples-progrmmatically.zip

    1. Clone https://github.com/Unity-Technologies/arfoundation-samples/tree/4.1
    2. Build scene TogglePlaneDetection to test that it works.
    3. Disable "Project Settings > XR Plug-in Management > Initialize On Start-Up".
    4. Load XR plugin at index 0 programmatically (snippet bellow).
    5. Result: black screen, so no plane detection.
    *Expected: the camera should switch on and detected planes should appear on the environment.

    Code (CSharp):
    1. public void StartXR(int loaderIndex, Action<bool> onFinish = null)
    2.     {
    3.         if (m_SelectedXRLoader != null)
    4.         {
    5.             StopXR();
    6.         }
    7.  
    8.         m_SelectedXRLoader = XRGeneralSettings.Instance.Manager.activeLoaders[loaderIndex];
    9.         StartCoroutine(StartXRCoroutine(onFinish));
    10.     }
    11.  
    12.  
    13.  
    14.  
    15.     IEnumerator StartXRCoroutine(Action<bool> onFinish)
    16.     {
    17.         Debug.Log("*** Init XR loader: " + m_SelectedXRLoader);
    18.  
    19.         var initSuccess = m_SelectedXRLoader.Initialize();
    20.         if (!initSuccess)
    21.         {
    22.             Debug.LogError("*** Error initializing selected loader.");
    23.             onFinish?.Invoke(false);
    24.             yield break;
    25.         }
    26.  
    27.         Debug.Log("*** Start XR loader");
    28.         var startSuccess = m_SelectedXRLoader.Start();
    29.         if (!startSuccess)
    30.         {
    31.             Debug.LogError("*** Error starting selected loader.");
    32.             m_SelectedXRLoader.Deinitialize();
    33.             onFinish?.Invoke(false);
    34.             yield break;
    35.         }
    36.  
    37.         onFinish?.Invoke(true);
    38.     }

    Attempts

    1. Without changing anything in the scene, just adding the manual XRLoader code, doesn't work --> black screen.
    2. Delaying ARSession and ARSessionOrigin activation after the XR plugin is loaded successfully --> black screnn; there is an infinite loop because ARSession.state = None.
    3. Loading the XR plugin in a scene and changing to the plane detection scene 1 second later (just in case) --> black screen and log bellow

    No active UnityEngine.XR.ARSubsystems.XRSessionSubsystem is available. Please ensure that a valid loader configuration exists in the XR project settings.
    W/Unity : UnityEngine.XR.ARFoundation.SubsystemLifecycleManager`3:GetActiveSubsystemInstance()
    W/Unity : UnityEngine.XR.ARFoundation.SubsystemLifecycleManager`3:EnsureSubsystemInstanceSet()
    W/Unity : UnityEngine.XR.ARFoundation.ARSession:OnEnable()
    W/Unity :
    W/Unity : No ARSession available for the current platform. Please ensure you have installed the relevant XR Plugin package for this platform via the Package Manager.
    W/Unity :
    W/Unity : No active UnityEngine.XR.ARSubsystems.XRCameraSubsystem is available. Please ensure that a valid loader configuration exists in the XR project settings.
    W/Unity : UnityEngine.XR.ARFoundation.SubsystemLifecycleManager`3:GetActiveSubsystemInstance()
    W/Unity : UnityEngine.XR.ARFoundation.SubsystemLifecycleManager`3:EnsureSubsystemInstanceSet()
    W/Unity : UnityEngine.XR.ARFoundation.SubsystemLifecycleManager`3:OnEnable()
    W/Unity :
    W/Unity : No active UnityEngine.XR.XRInputSubsystem is available. Please ensure that a valid loader configuration exists in the XR project settings.
    W/Unity : UnityEngine.XR.ARFoundation.ARInputManager:GetActiveSubsystemInstance()
    W/Unity : UnityEngine.XR.ARFoundation.ARInputManager:OnEnable()
    W/Unity :
    W/Unity : No active UnityEngine.XR.ARSubsystems.XRPlaneSubsystem is available. Please ensure that a valid loader configuration exists in the XR project settings.
    W/Unity : UnityEngine.XR.ARFoundation.SubsystemLifecycleManager`3:GetActiveSubsystemInstance()
    W/Unity : UnityEngine.XR.ARFoundation.SubsystemLifecycleManager`3:EnsureSubsystemInstanceSet()
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,661
unityunity