Hello, I'm working on a geo-referenced app, to discover some AR placeholders in several locations. To preserve the battery I think to disable ARCore while the player is just walking to the new location (but the app must stay open because there's a map in it that show the placeholders positions). 1) So to disable ARcore I use -- arcoreSession.enabled = false; 2) Next. to enable it again I use -- arcoreSession.enabled = true; 3) At the same time I have to reset AR camera position (to 0,0,0) and orientation, so I use -- LifecycleManager.Instance.ResetSession(); My issue is that this is working only once, the 2nd time I get the error "Trying to access a session that has already been destroyed" Is there a way to safely reset the ARCore session, so to be able to repeat this workflow as many times as needed? Thank-you!
If someone is interested I've made this code and it seem to work as expected Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class ARCoreSessionManagement : MonoBehaviour { [SerializeField] GameObject arCoreSessionPrefab; private GameObject newArCoreSessionPrefab; private GoogleARCore.ARCoreSession arcoreSession; private void Start() { newArCoreSessionPrefab = Instantiate(arCoreSessionPrefab, Vector3.zero, Quaternion.identity); arcoreSession = newArCoreSessionPrefab.GetComponent<GoogleARCore.ARCoreSession>(); arcoreSession.enabled = true; } public void Reset() { StartCoroutine(CreateANewSession()); } IEnumerator CreateANewSession() { //Destroy arcoreSession.enabled = false; if (newArCoreSessionPrefab != null) Destroy(newArCoreSessionPrefab); yield return new WaitForSeconds(1); //Create a new one newArCoreSessionPrefab = Instantiate(arCoreSessionPrefab, Vector3.zero, Quaternion.identity); arcoreSession = newArCoreSessionPrefab.GetComponent<GoogleARCore.ARCoreSession>(); arcoreSession.enabled = true; } }