Restarting scene get black screen on AR-Foundation Android

Restarting scene get black screen on AR-Foundation Android

I am working on a semi-old solution with unity 2020.3 that is using arfoundation.

On the first start of the AR scene everything works fine, BUT if I try to reopen the AR scene I get the black screen and get this error:

no active unityengine.xr.arsubsystems.xrsessionsubsystem is available

I already tried:

-reload scene
-reload a second scene and then reload the first one.
-destroy the objects before reload scene:

yield return new WaitForSeconds(1f);
           var cameraManager = FindObjectOfType<ARCameraManager>();
           if (cameraManager != null)
               Destroy(cameraManager.gameObject);
            yield return new WaitForSeconds(1f);
            ARSession arSession = FindObjectOfType<ARSession>();
           if (arSession != null)
               Destroy(arSession.gameObject);

-restart ar subsistem

XRGeneralSettings.Instance.Manager.StopSubsystems();
XRGeneralSettings.Instance.Manager.DeinitializeLoader();
yield return null; // Attendi un frame
XRGeneralSettings.Instance.Manager.InitializeLoaderSync();
XRGeneralSettings.Instance.Manager.StartSubsystems();

-deinizialize loader

 var xrManagerSettings = XRGeneralSettings.Instance.Manager;
        xrManagerSettings.DeinitializeLoader();
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); // reload current scene
        xrManagerSettings.InitializeLoaderSync();

NOTHING seems to work and I do not know what else to do

any advice or solution?? Please help!!

You didn’t indicate AR Foundation version you use, but in ARF 5 we use these 2 files. Just place them in Assets folder:

  1. arfoundation-samples/Assets/Scripts/Runtime/SceneUtility.cs at 5.1 · Unity-Technologies/arfoundation-samples · GitHub
  2. arfoundation-samples/Assets/Scripts/Runtime/SceneUtilitySetup.cs at 5.1 · Unity-Technologies/arfoundation-samples · GitHub

Hello lkaro881,

The working AR Foundation package for Unity 2020:

… is 4.1. So the first question to ask would be which version(s) of AR Foundation are you encountering this issue with?

Having said that, the scene setup resources that makaka-org referenced may prove to be helpful.

Bear in mind that AR Foundation 4.1 has fallen out of official support, as has Unity 2020.

Also Unity 2020 is no longer supported so I would definitely suggest updating your project.

To add to Ciaran’s note, the current minimum supported LTS version of Unity is 2022.3.