Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    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:
    5
    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. KirillKuzyk

    KirillKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    112
    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:
    5
    planeManager.trackables.count keeps automatically count of updated, added and removed planes right?
     
unityunity