Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.04k stars 1.14k forks source link

[Bug] Unable to initialize XR at runtime on iOS 17.2.1 #1144

Closed dilnuryuldashev closed 8 months ago

dilnuryuldashev commented 9 months ago

Hi,

I want to start XR manually at runtime, so I unchecked "Initialize XR on Startup". Cloned this repo, and picked the Simple AR Scene, and when I run the StartXRCoroutine coroutine from the source below, I get nothing but a black screen: https://docs.unity3d.com/Packages/com.unity.xr.management@4.4/manual/EndUser.html

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:DoProcess()

    // 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.

andyb-unity commented 9 months ago

Initializing XR alone does not cause anything to be rendered to the screen. After initializing XR, you would need to enable an ARSession, XROrigin, ARCameraManager, and ARCameraBackground. Refer to Scene setup for more information about the necessary components.

If these components were in your scene before you initialized XR, they would all disable themselves upon discovering that XR was not initialized, and you need to re-enable them.

dilnuryuldashev commented 8 months ago

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.