How to stop plane detection and delete all planes in ARCore 1.9 using Unity?

Viewed 1861

I am looking to tap on screen and show a model.When plane is detected,I tap the device screen to display the model.The problem occurs when planes showing in the scene is awkward and it goes detecting planes again.Similar to ARkit is there any events to remove anchors from scene.When I place the model on the detected plane with touch,I am calling for a method to turnoff plane detection and delete planes.It is not working.Code given below.

//Method call to turn of plane detection n delete already detected planes
 DetectedPlaneGenerator.DPGenaratorInstance.DeletePlanes();

Detected plane Generator class where I have written methods to turn off plane detection and delete already found planes.

 public class DetectedPlaneGenerator : MonoBehaviour
{
    /// <summary>
    /// A prefab for tracking and visualizing detected planes.
    /// </summary>
    public GameObject DetectedPlanePrefab;
    GameObject planeObject;
    public Text Msgtxt;

    /// <summary>
    /// A list to hold new planes ARCore began tracking in the current frame. This object is
    /// used across the application to avoid per-frame allocations.
    /// </summary>
    private List<DetectedPlane> m_NewPlanes = new List<DetectedPlane>();

    /// <summary>
    /// The Unity Update method.
    /// </summary>
    /// 

    public static DetectedPlaneGenerator DPGenaratorInstance;



    private void Start()
    {
        DPGenaratorInstance = this;
    }
    public void Update()
    {
        // Check that motion tracking is tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            return;
        }

        // Iterate over planes found in this frame and instantiate corresponding GameObjects to
        // visualize them.
        Session.GetTrackables<DetectedPlane>(m_NewPlanes, TrackableQueryFilter.New);
        for (int i = 0; i < m_NewPlanes.Count; i++)
        {
            // Instantiate a plane visualization prefab and set it to track the new plane. The
            // transform is set to the origin with an identity rotation since the mesh for our
            // prefab is updated in Unity World coordinates.
             planeObject =
                Instantiate(DetectedPlanePrefab, Vector3.zero, Quaternion.identity, transform);
            planeObject.GetComponent<DetectedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
        }
    }


    public void DeletePlanes()
    {
        StopTracking();
        for (int i = 0; i < m_NewPlanes.Count; i++)
        {
            Destroy(planeObject);
        }

    }


    public void StopTracking()
    {
        int i = 0;
        //Msgtxt.text = i.ToString();

        foreach (GameObject plane in GameObject.FindGameObjectsWithTag("Plane"))
        {
            Renderer r = plane.GetComponent<Renderer>();
            DetectedPlaneVisualizer t = plane.GetComponent<DetectedPlaneVisualizer>();
            r.enabled = false;
            t.enabled = false;
           // Msgtxt.text = i.ToString();
            i++;//to check whether it is looping-no luck
        }


    }

}
1 Answers

You Can Reset ARSession for deleting all planes

public ARSession session; 
public void ResetArSession(Scene scene)
{
    session.Reset();
    EntityManager.instance.DestroyAllEntity();
}
Related