What's the proper way to manually remove a XR Anchor?

Hey there,
I’m trying to manually remove a tracked XRAnchor from the scene under some condition, but I’m getting an error using the ‘remove()’ function - IWebXRAnchor | Babylon.js Documentation.

Here is the error:

Uncaught (in promise) TypeError: Illegal invocation

I’m not entirely sure that I understand how to properly remove the anchor.
From what I’ve gathered from the Docs page linked above and this other page (WebXRAnchorSystem | Babylon.js Documentation):
Calling the
.anchors property on the returned WebXRAnchorSystem would return an array of the available/existing Anchors.
So, I guess that if I’d write something like:

would remove the anchor that’s present in the first index of that array.
But I’m getting the error pasted above and I don’t quite understand why or what it means.

Any suggestions that would help clarify the best approach to do this would be greatly appreciated!


This is the proper way to remove an anchor. It is removed async, so the object might still be in the array right after the remove call (the way the API works).

Would you be able to reproduce this on the playground? Would be great to see what happens here.

Hey there!
Thank you for replying!
I tried testing it within the Playground Demo that’s in the WebXR Docs (Babylon.js Playground) and there is no auto complete to access the ‘anchors’ object from the Anchor System.
Just tried duplicating that demo to a new one and it doesn’t work.
I get the same ‘illegal invocation’ error in the console.

Here is the test PLayground:

Everything is a copy-paste from the original Docs Demo, just added the condition to trigger the remove() function on the input PointerDown.
The idea was to remove the existing anchor on the second tap/click.

1 Like

I will look into it! Thanks :slight_smile:

1 Like

Thank you!
Idk if it makes sense to ask this here, but I’ve got no answer in this other thread either. If it wouldn’t be asking too much could you see if I’m doing something wrong with this issue as well? Issues importing GLTF models in a WebXR (AR) Immersive Scene.