arfoundation-samples icon indicating copy to clipboard operation
arfoundation-samples copied to clipboard

Removing planes

Open AndreasLangberg opened this issue 7 years ago • 3 comments

It seems like there currently are implemented events in the condition that a plane is removed, but with no actual way to remove them except to reset the whole ARSession (Which also resets the camera and removes all other trackables). If you manually destroy planes then ARPlaneManager hits you with the error below every frame you try to add another plane at the same location as the previous. Even if you remove the manager completely and add a new one, it's not able to retrack a surface you have previously tracked.

ArgumentException: An item with the same key has already been added. Key: D04E208B120CD64E-8FF5A5DD81B1B4B2

  at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x00000] in <00000000000000000000000000000000>:0

  at UnityEngine.XR.ARFoundation.ARPlaneManager.AddPlane (UnityEngine.Experimental.XR.BoundedPlane boundedPlane) [0x00000] in <00000000000000000000000000000000>:0

  at UnityEngine.XR.ARFoundation.ARPlaneManager.OnPlaneUpdated (UnityEngine.Experimental.XR.PlaneUpdatedEventArgs eventArgs) [0x00000] in <00000000000000000000000000000000>:0

  at System.Action`1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0

  at UnityEngine.XR.ARFoundation.ARSubsystemManager.OnPlaneUpdated (UnityEngine.Experimental.XR.PlaneUpdatedEventArgs eventArgs) [0x00000] in <00000000000000000000000000000000>:0

  at System.Action`1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0

  at UnityEngine.Experimental.XR.XRPlaneSubsystem.InvokePlaneUpdatedEvent (UnityEngine.Experimental.XR.BoundedPlane plane) [0x00000] in <00000000000000000000000000000000>:0

(Filename: currently not available on il2cpp Line: -1)

AndreasLangberg avatar Apr 16 '19 07:04 AndreasLangberg

Believe it or not, this is intended behavior–– in order to properly abstract cross platform, ARFoundation seems to be manipulating plane data largely at the game object level once it's been created. So once you've got the planes, you can just turn off their renderer, or turn off the whole game object. But you really wouldn't want to destroy them, since ARFoundation wouldn't really have a way of bridging the created gameobject instance with the internal representation of the plane. Imagine if you destroyed the object in ARKit -- how would you know what to do with that area? Put another plane there? Ignore any planes that try to update near it? Not good flow.

gpt3-bot avatar May 16 '19 17:05 gpt3-bot

@shawmakesmusic is correct -- if you just want to hide existing planes, you can disable them with this example.

tdmowrer avatar Oct 07 '19 00:10 tdmowrer

I want to trigger that after 30 sec of livetime a plane gets removed. Is there a way for this without restarting the AR Session? If I simply disable the Plane or its Renderer then a new Plane will not be created (It will just extend the hidden one)

Augmentaio avatar Jun 10 '20 13:06 Augmentaio