The web xr motion controller teleportation can throw in its _onXRFrame

Hi, I came across a little bug where WebXRMotionControllerTeleportation will throw with the following error “Uncaught TypeError: Cannot read property ‘teleportationState’ of undefined” in its _onXRFrame.

This happens when a teleportation timer is started and the user leaves the XR session, after this upon re-entering the XR session the _onXRFrame throws. Apparently this is due to _currentTeleportationControllerId being set by the timer but it will not be cleared upon exiting the session, now after re-entering the session, the _currentTeleportationControllerId is still set but no controllers exist yet. The line that throws is Babylon.js/WebXRControllerTeleportation.ts at master · BabylonJS/Babylon.js · GitHub

This was reproducible in the playground using GearVR as well as the WebXR emulator. Basically if you leave the XR session when the following is happening


and try to re-enter the session, it will throw.

I managed to get it fixed in my application by setting _currentTeleportationControllerId to an empty string (same thing that is done after teleportation is finished) when an XR session ends. So I guess you could add an observer to xrSessionManager’s onXRSessionEnded which would clear the state properly?

Sure! Will solve that asap.

Thanks for reporting!

1 Like

Done - [XR] Teleportation fix and optional required features by RaananW · Pull Request #8499 · BabylonJS/Babylon.js · GitHub , will be merged soon

1 Like

Thanks for the quick response and fix

1 Like