ARFoundation plane count

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?

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?

1 Like

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!

You can simply get count of ARPlaneManager trackables.

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

planeManager.trackables.count keeps automatically count of updated, added and removed planes right?

For the total count of planed added, updated and removed, you would use something like :
csharp* *void planNum(ARPlanesChangedEventArgs args) { Debug.Log("planes Added = " + args.added.Count + " planes removed = " + args.removed.Count + " planes updated = " + args.updated.Count); }* *

This post does address the removal of planes in detail:
https://discussions.unity.com/t/739564