Search Unity

GetAllPlanes() proper usage

Discussion in 'AR' started by alexanderFabula, Sep 25, 2019.

  1. alexanderFabula

    alexanderFabula

    Joined:
    Sep 1, 2019
    Posts:
    22
    Hi.

    I'm having trouble figuring out the proper way to use ARPlaneManager.GetAllPlanes().

    I need to collect the position of the AR Planes in my scene. More specific I need to update an output position that I need for object placement.

    I've pasted my update function below. When I run this on m device the currentPlanes.count keeps printing 0.

    Code (CSharp):
    1. private void Update()
    2.     {
    3.         if (planeDetectionIsLive)
    4.         {
    5.             arPlaneManager.GetAllPlanes(currentPlanes);
    6.             Debug.Log("Plane Count: " + currentPlanes.Count);
    7.  
    8.             if (currentPlanes.Count > detectedPlanesCount)
    9.             {
    10.                 if (!planeIsDetected)
    11.                 {
    12.                     planeIsDetected = true;
    13.                 }
    14.  
    15.                 // Set plane position to last plane in currentPlanes
    16.                 planePosition = currentPlanes[-1].transform.position;
    17.  
    18.                 detectedPlanesCount = currentPlanes.Count;
    19.  
    20.                 Debug.Log("New plane is detected, amount of planes: " + detectedPlanesCount);
    21.  
    22.             }
    23.         }
    24.     }
    25.  
     
  2. alexanderFabula

    alexanderFabula

    Joined:
    Sep 1, 2019
    Posts:
    22
    I have a similar problem with the planeAdded, planeUpdated and planeRemoved events. They are never called.


    Code (CSharp):
    1. public void StartPlaneDetection()
    2.     {
    3.         if (arPlaneManager == null)
    4.         {
    5.             arPlaneManager = AR_SESSION_ORIGIN.GetComponent<ARPlaneManager>();
    6.         }
    7.  
    8.         arPlaneManager.enabled = true;
    9.         planeDetectionIsLive = true;
    10.  
    11.         arPlaneManager.planeAdded += ArPlaneManager_PlaneAdded;
    12.  
    13.         Debug.Log("Start AR Plane Detection");
    14.  
    15.     }
    16.  
    17.     void ArPlaneManager_PlaneAdded(ARPlaneAddedEventArgs obj)
    18.     {
    19.         Debug.Log("Plane is added with y pos: " + obj.plane.transform.position.y);
    20.     }
    21.  
     
  3. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    590