Start XR Manually

Hi,

I want to start XR manually at runtime, so I unchecked “Initialize XR on Startup”.
Downloaded the sample scenes from Github: GitHub - Unity-Technologies/arfoundation-samples: Example content for Unity projects based on AR Foundation
Picked the Simple AR Scene, and when I run the StartXRCoroutine coroutine from the source below, I get nothing but a black screen:
Advanced configuration for plug-in management | XR Plugin Management | 4.4.1

    public IEnumerator StartXRCoroutine()
    {
        Debug.Log("Initializing XR...");
        yield return XRGeneralSettings.Instance.Manager.InitializeLoader();

        if (XRGeneralSettings.Instance.Manager.activeLoader == null)
        {
            Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
        }
        else
        {
            Debug.Log("Starting XR...");
            XRGeneralSettings.Instance.Manager.StartSubsystems();
        }
    }

Even though XCode seems to be fine:

Initializing XR...
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
<StartXR>d__6:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
UnityEngine.Events.UnityEvent:Invoke()
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.XR.Interaction.Toolkit.UI.UIInputModule:ProcessPointerButton(ButtonDeltaState, PointerEventData)
UnityEngine.XR.Interaction.Toolkit.UI.UIInputModule:ProcessTouch(TouchModel&)
UnityEngine.XR.Interaction.Toolkit.UI.XRUIInputModule:ProcessTouches()
UnityEngine.XR.Interaction.Toolkit.UI.XRUIInputModule:smile:oProcess()


    // 2D joint skeleton
    enum JointIndices
    {
        Invalid = -1,
        Head = 0, // parent: Neck1 [1]
        Neck1 = 1, // parent: Root [16]
       .....
    }

    // 3D joint skeleton
    enum JointIndices
    {
        Invalid = -1,
        Root = 0, // parent: <none> [-1]
        Hips = 1, // parent: Root [0]
.......
  }
[Subsystems] Loading plugin UnityARKit for subsystem ARKit-Input...
[Subsystems] UnityARKit successfully registered Provider for ARKit-Input
[Subsystems] Loading plugin UnityARKit for subsystem ARKit-Meshing...
[Subsystems] Failed to initialize subsystem ARKit-Meshing [error: 1]
Starting XR...
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
<StartXR>d__6:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

The only issue I noticed above is the [Subsystems] Failed to initialize subsystem ARKit-Meshing [error: 1] part. I wonder if it affects anything.

How can I start XR manually at runtime?

Unity 2023.2.3f1. iPhone 11. iOS 17.2.1
Custom project AR Plugin versions: AR Foundation 5.1.1. ARKit 5.1.1.
AR Foundation Samples Github Project AR Plugin versions: 6.0.0-pre.5

Thanks.

Please do not double post. [Bug] Unable to initialize XR at runtime on iOS 17.2.1 · Issue #1144 · Unity-Technologies/arfoundation-samples · GitHub

1 Like

Apologize for that. We have to publish the app by January 15th, so it was really urgent.

I tackled this issue differently. I have two separate scenes now, one AR Scene, and one non-AR Scene. I request the Camera permission in the non-AR scene manually, and then go to the AR Scene. But thanks for explaining how this is supposed to work.

I just did not like the Camera permission pop-up as soon as the AR Scene opens up, not a great UX. That’s why, I separated all device permissions into the non-AR Scene.

Cool! I like the way you set that up.