Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

ARFoundation plane count

Discussion in 'AR' started by aronindan, Jan 19, 2020.

  1. aronindan

    aronindan

    Joined:
    Jan 19, 2020
    Posts:
    2
    Hi all, I'm new to Unity and c#. I want to make a script that would detect planes and return how many were detected.

    I think I should use ARPlanesChangedEventArgs based on what I found here but I still don't understand how to use this.

    Here is something I thought of but doesn't work:

    void Update()
    {
    planeNum();

    }

    void planeNum (ARPlanesChangedEventArgs args)
    {
    print(args.added.Count);

    }

    any suggestions?
     
  2. VR_learner

    VR_learner

    Joined:
    Sep 16, 2018
    Posts:
    1
    I'm a beginner somehow but i think you need to implement the 'planesChanged' callback from the ARPlaneManager class.

    need a reference to an instance

    private ARPlaneManager aRPlaneManager;

    then

    aRPlaneManager.planesChanged += planeNum;

    then

    void planeNum (ARPlanesChangedEventArgs args)
    {
    print(args.added.Count);
    }


    I made it like this and it worked
    but what I can't understand is removed and updated
    how the planes will be removed?
    is there is a way to remove a plane so that i can count it?
     
    sristi likes this.
  3. riccardokhm

    riccardokhm

    Joined:
    Oct 22, 2019
    Posts:
    9
    I am trying to implement the same thing, i am using your code, but i think probably the best way is to refer not to "added" list but to the "updated" one when calling the event. I am trying and i'll let you know!
     
  4. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,146
    You can simply get count of ARPlaneManager trackables.

    var planeManager = FindObjectOfType<ARPlaneManager>();
    var planesCount = planeManager.trackables.count;
     
  5. riccardokhm

    riccardokhm

    Joined:
    Oct 22, 2019
    Posts:
    9
    planeManager.trackables.count keeps automatically count of updated, added and removed planes right?
     
  6. AjBaruah

    AjBaruah

    Joined:
    Mar 14, 2019
    Posts:
    8
    For the total count of planed added, updated and removed, you would use something like :
    Code (CSharp):
    1. void planNum(ARPlanesChangedEventArgs args)
    2.     {
    3.         Debug.Log("planes Added = " + args.added.Count + " planes removed = " + args.removed.Count + " planes updated = " + args.updated.Count);
    4.     }
     
    Last edited: Aug 9, 2020
  7. AjBaruah

    AjBaruah

    Joined:
    Mar 14, 2019
    Posts:
    8