I tried to use this in, but it seems it does not do anything:
ARSubsystemManager.DestroySubsystems();
ARSubsystemManager.CreateSubsystems();
Sometimes the tracking goes wrong or when reopening an app all es messed up and I want to give the users to reset the scene. Then all planes have to removed and the tracking points and so on.
For ARKit I had a script that can do this, but now with foundation it seems a bit more difficult.
Did this work for you? I tried this but when but i get this error when enabeling the newly spawned arsession: InvalidOperationException: Cannot start AR session because there is no session subsystem
Same here, “InvalidOperationException: Cannot start AR session because there is no session subsystem.” when enabling ARSession. I also get it if I load from SampleScene to another scene and then try to load SampleScene again.
I’m also getting a black screen, instead of the camera feed, after destroying the ARSession component and then adding it back to the same gameObject.
If I’m reloading AR scene for the second time, I’m getting the "Cannot start AR session…" error, and device is not tracking any planes, due to session fail
I have the same issue when loading scene again. Just one note that I’m using multiple scenes loaded additively and AR session lives in the scene from scene load.
I can’t already reproduce this exact error, it’s been lost in the iterations of fixing attempts.
The thing is I was trying to fix nonexistent error, because it was only in the Editor, as soon as I built my app for device, everything went okay.
I used directives for ARSubsystemManager functions, because all of the systems are null in the editor, therefore it can’t function properly.
So it looks like this and works like charm even when reloading scene:
void Start()
{
#if !UNITY_EDITOR
ARSubsystemManager.DestroySubsystems();
ARSubsystemManager.CreateSubsystems();
ARSubsystemManager.StopSubsystems();
arSession.gameObject.SetActive(false);
#endif
}
public async void StartTracking()
{
#if !UNITY_EDITOR
arSession.gameObject.SetActive(true);
ARSubsystemManager.StartSubsystems();
arPlaneManager.planeAdded += PlaneTracked;
#else
//here comes some emulation of plane tracking for Editor:
//PlaceInfinitePlane(Vector3.zero);
//await new WaitForSeconds(1f);
//OnPlaneTracked?.Invoke();
#endif
}
May it help someone to figure out how to handle reload of ar session =)
We’re also having the same issue with reloading the scene a second time and getting a black screen. Samsung S8 and Android, and iPhone 7 Plus and iOS 12
But how we can call that method? I have a button that calls “ResetDemo” function to load the firstScene and reset the ARKit but doestn works :
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using UnityEditor;
using UnityEngine.SceneManagement;
public class HumanBodyTracker : MonoBehaviour
{
....
private void Reset() {
Debug.Log("Reseting....");
}
public void ResetDemo()
{
Reset();
SceneManager.LoadScene("StartScene");
Debug.Log("Loading Start Scene...");
message = "Loading Start Scene...";
}
You have to get a reference to the ARSession in your scene to be able to call the Reset(). You can either get it by placing your script on the same GameObject, as the ARSession is on
The Reset() works fine, if you don’t leave the scene and stay in the AR-scene. As I can see from your posting you are then also loading another scene within your special reset, so this causes the black screen. Comment that out, so your app stays in the same scene and try the reset again.
The problems stays the same: If you leave an AR-scene and later return to an AR-scene the background is just black