Search Unity

Question Switching ARFoundatin (ARCore / ARKit) <-> Google Cardboard doesn't work

Discussion in 'AR' started by LuisJavierLopez, Aug 31, 2021.

  1. LuisJavierLopez

    LuisJavierLopez

    Joined:
    May 23, 2019
    Posts:
    8
    We need some help to initInitializing a XR Loader programmatically, ad-hoc. Thanks in advance.

    Unity: 2020.3.14f1

    ARFoundation: 4.1.7

    Google CardBoard SDK: 1.7.0

    Requirement

    We need to have ARFoundation and Google Cardboard loaders in the project, in different scenes. We start in a scene without any XR Loader initialized, and we need to load each of them when loading different scenes.

    Problem

    Although we have both XR loaders included in the XR Plugin Manager, we are note able to initialize one of them programatically.



    This works (not enough)
    Automatic XR loading. This works when there's only one XRLoader checked in the settings of Unity (ARCore or Cardboard).

    Warning (ARFoundation): ARSession had to be enabled when initialization was completed, ARSessionOrigin game object is initially deactivated and it is activated when tracking is available, and ARInputManager component was moved from ARSession's gameobject to ARSessionOrigin's one.

    This should work (it doesn't)

    Automatic XR loading for specific XR loaders. That code, initializes the XRLoader, but does not start the subsystems, so no XR functionality is provided.

    Code (CSharp):
    1. if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    2. {
    3.    Debug.LogError("*** Initializing XR Failed. Check Editor or Player log for details.");
    4.    yield break;
    5. }
    activeLoader is always null, so we cannot start subystems.

    Code (CSharp):
    1. XRGeneralSettings.Instance.Manager.StartSubsystems();
    XRGeneralSettings.Instance.Manager.StartSubsystems();

    long snippet


    Code (CSharp):
    1. XRLoader m_SelectedXRLoader;
    2.  
    3.    public void StartXR(int loaderIndex)
    4.    {
    5.        if (m_SelectedXRLoader != null)
    6.        {
    7.            StopXR();
    8.        }
    9.  
    10.        m_SelectedXRLoader = XRGeneralSettings.Instance.Manager.activeLoaders[loaderIndex];
    11.        StartCoroutine(StartXRCoroutine());
    12.    }
    13.  
    14.    IEnumerator StartXRCoroutine()
    15.    {
    16.        Debug.Log("*** Init XR loader");
    17.  
    18.        var initSuccess = m_SelectedXRLoader.Initialize();
    19.        if (!initSuccess)
    20.        {
    21.            Debug.LogError("*** Error initializing selected loader.");
    22.            yield break;
    23.        }
    24.  
    25.        Debug.Log("*** Start XR loader");
    26.        var startSuccess = m_SelectedXRLoader.Start();
    27.        if (!startSuccess)
    28.        {
    29.            Debug.LogError("*** Error starting selected loader.");
    30.            m_SelectedXRLoader.Deinitialize();
    31.            yield break;
    32.        }
    33.  
    34.        //yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    35.  
    36.        if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    37.        {
    38.            Debug.LogError("*** Initializing XR Failed. Check Editor or Player log for details.");
    39.            yield break;
    40.        }
    41.  
    42.        Debug.Log("*** Starting Subsystems XR...");
    43.        XRGeneralSettings.Instance.Manager.StartSubsystems();
    44.    }
    logcat

    I/Unity : *** Init XR loader I/Unity : UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37) I/Unity : UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) I/Unity : UnityEngine.Logger:Log (UnityEngine.LogType,object) I/Unity : UnityEngine.Debug:Log (object) I/Unity : Utils.RuntimeXRLoaderManager/d__6:MoveNext () (at /Users/many-worlds/Documents/Projects/GlobalProAndroid/Assets/_project/Scripts/Utils/VR/RuntimeXRLoaderManager.cs:27) I/Unity : UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17) I/Unity : UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/MonoBehaviour.bindings.cs:91) I/Unity : Utils.RuntimeXRLoaderManager:StartXR (int) (at /Users/many-worlds/Documents/Projects/GlobalProAndroid/Assets/_project/Scripts/Utils/VR/RuntimeXRLoaderManager.cs:22) I/Unity : Glob D/Unity : [Subsystems] Loading plugin UnityARCore for subsystem ARCore-Input... I/Unity : *** Start XR loader I/Unity : UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37) I/Unity : UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) I/Unity : UnityEngine.Logger:Log (UnityEngine.LogType,object) I/Unity : UnityEngine.Debug:Log (object) I/Unity : Utils.RuntimeXRLoaderManager/d__6:MoveNext () (at /Users/many-worlds/Documents/Projects/GlobalProAndroid/Assets/_project/Scripts/Utils/VR/RuntimeXRLoaderManager.cs:36) I/Unity : UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17) I/Unity : UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/MonoBehaviour.bindings.cs:91) I/Unity : Utils.RuntimeXRLoaderManager:StartXR (int) (at /Users/many-worlds/Documents/Projects/GlobalProAndroid/Assets/_project/Scripts/Utils/VR/RuntimeXRLoaderManager.cs:22) I/Unity : Glo E/Unity : *** Initializing XR Failed. Check Editor or Player log for details. E/Unity : UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37) E/Unity : UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) E/Unity : UnityEngine.Logger:Log (UnityEngine.LogType,object) E/Unity : UnityEngine.Debug:LogError (object) E/Unity : Utils.RuntimeXRLoaderManager/d__6:MoveNext () (at /Users/many-worlds/Documents/Projects/GlobalProAndroid/Assets/_project/Scripts/Utils/VR/RuntimeXRLoaderManager.cs:49) E/Unity : UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17) E/Unity : UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/MonoBehaviour.bindings.cs:91) E/Unity : Utils.RuntimeXRLoaderManager:StartXR (int) (at /Users/many-worlds/Documents/Projects/GlobalProAndroid/Assets/_proje W/Unity : No active UnityEngine.XR.ARSubsystems.XRSessionSubsystem is available. Please ensure that a valid loader configuration exists in the XR project settings. W/Unity : UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37) W/Unity : UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) W/Unity : UnityEngine.Logger:LogFormat (UnityEngine.LogType,string,object[]) W/Unity : UnityEngine.Debug:LogWarningFormat (string,object[]) W/Unity : UnityEngine.XR.ARFoundation.SubsystemLifecycleManager3<UnityEngine.XR.ARSubsystems.XRSessionSubsystem, UnityEngine.XR.ARSubsystems.XRSessionSubsystemDescriptor, UnityEngine.XR.ARSubsystems.XRSessionSubsystem/Provider>:GetActiveSubsystemInstance () (at /Users/many-worlds/Documents/Projects/GlobalProAndroid/Library/PackageCache/com.unity.xr.arfoundation@4.1.7/Runtime/AR/SubsystemLifecycleManager.cs:68) W/Unity : UnityEngine.XR.ARFoundation.SubsystemLifecycleManager3<UnityEngine.XR.ARSubsystems.XRSessionSubsystem, UnityEngin 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 : UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37) W/Unity : UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) W/Unity : UnityEngine.Logger:LogFormat (UnityEngine.LogType,string,object[]) W/Unity : UnityEngine.Debug:LogWarningFormat (string,object[])
     

    Attached Files:

  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    Hey there! So, Google Cardboard is no longer directly supported by Unity. The Google team has asked that you post questions and issues on their Github so that their team can address.
     
  3. LuisJavierLopez

    LuisJavierLopez

    Joined:
    May 23, 2019
    Posts:
    8
    Hi! In fact, this is not an issue with Google Cardboard. This issue is related with ARFoundation, because I cannot load ARFoundation programmatically

    This happens even without Google Cardboard plugin checked in the "XR Plug-int Mangement" settings.
     
    Last edited: Sep 1, 2021
  4. LuisJavierLopez

    LuisJavierLopez

    Joined:
    May 23, 2019
    Posts:
    8
    Forget about Google Cardboard, this is reproduced just using ARFoundation package. I have provided further information with tests and logs in this porst: https://forum.unity.com/threads/arf...loading-it-programmatically-by-index.1164566/