Open michelesandroni opened 1 year ago
Did you try creating a button, then on click() event drag and drop your AR Session then call from AR Session-> Reset() method?
Did you ever find a solution? I also can not figure out how to completely restart an AR session... https://github.com/Unity-Technologies/arfoundation-samples/issues/1107
By Adding SceneUtility.cs & SceneUtilitySetup.cs from this repo to my project, I could get rid of the error when switching scenes in the Editor: "MissingReferenceException: The object of type 'Camera' has been destroyed but you are still trying to access it."
My Scene is loaded 2nd time successfully, and shows the simulated environment, cloud points are shown upon Plane Detection, but Planes are not recognized... They can be recognized in a random moment after randomly moving in the scene after 15, 20, 60... seconds.
I have no issues on Mobiles, only in the Editor.
So, the issue is the same for 2nd, 3rd, so on reloading of the scene.
P.S. I use the Default Simulated Environment for the testing.
@makakaorg - We recently fixed a bug in 5.1.2 patch version which should fix the plane detection issue that you are seeing.
Fixed an issue where calling
ARSession.Reset
could cause XR Simulation plane detection to fail to discover planes for a period of time before resuming.
https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@5.1/changelog/CHANGELOG.html#fixed
I struggled with this issue as well. I wonder till today, why there is no easy solution to put all AR stuff into a scene and load it during runtime (and undload/reload the scene if neccessary). <- for the simulated environment in Unity Editor I came up with this solution:
public void StartSession()
{
XRGeneralSettings instance = XRGeneralSettings.Instance;
if (instance != null)
{
StartCoroutine(instance.Manager.InitializeLoader());
instance.Manager.StartSubsystems();
}
}
public void EndSession()
{
XRGeneralSettings instance = XRGeneralSettings.Instance;
if (instance != null)
{
instance.Manager.DeinitializeLoader();
instance.Manager.StopSubsystems();
}
}
I call StartSession before I load an AR scene. And I call EndSession before I unload an AR scene. This way I have no issues with camera nullreference exceptions, Object disposed issues, ... in both, editor and Android. I am using AR Foundation 5.1.3
How do I correctly restart an AR scene in AR Foundation 5.0.6 using the scene manager? In other words I would like to reload the current active scene and also have all AR planes removed and the tracking session reset.
I know this has been asked before but after searching this repo and in unity forums I still came up with lots outdated solutions that don't seem to work consistently on either iOS or Android. I also couldn't find this clearly explained in the AR Foundation documentation.
I'm also using XR Simulation in the Editor on Windows which stops working after the scene is reloaded.