LuisJa
LuisJa

Reputation: 21

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

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.

XR Plugin Manager - Loaders

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, initialize the XRLoader, but does not start the subsystems, so no XR functionality is provided.

if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
    Debug.LogError("*** Initializing XR Failed. Check Editor or Player log for details.");
    yield break;
}

activeLoader is always null, so we cannot start subystems.

XRGeneralSettings.Instance.Manager.StartSubsystems();

long snippet

    XRLoader m_SelectedXRLoader;

    public void StartXR(int loaderIndex)
    {
        if (m_SelectedXRLoader != null)
        {
            StopXR();
        }

        m_SelectedXRLoader = XRGeneralSettings.Instance.Manager.activeLoaders[loaderIndex];
        StartCoroutine(StartXRCoroutine());
    }

    IEnumerator StartXRCoroutine()
    {
        Debug.Log("*** Init XR loader");

        var initSuccess = m_SelectedXRLoader.Initialize();
        if (!initSuccess)
        {
            Debug.LogError("*** Error initializing selected loader.");
            yield break;
        }

        Debug.Log("*** Start XR loader");
        var startSuccess = m_SelectedXRLoader.Start();
        if (!startSuccess)
        {
            Debug.LogError("*** Error starting selected loader.");
            m_SelectedXRLoader.Deinitialize();
            yield break;
        }

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

        if (XRGeneralSettings.Instance.Manager.activeLoader == null)
        {
            Debug.LogError("*** Initializing XR Failed. Check Editor or Player log for details.");
            yield break;
        }

        Debug.Log("*** Starting Subsystems XR...");
        XRGeneralSettings.Instance.Manager.StartSubsystems();
    }

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/[email protected]/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[])

Upvotes: 2

Views: 1222

Answers (1)

ARtyom
ARtyom

Reputation: 41

I have similar issue. during research and and some coding I have realized that XRGeneralSettings.Instance.Manager.loaders return the correct number or XR plugins. but active loaders shows only 1 item for me.

Upvotes: 0

Related Questions