Entering XR: automatically and camera position on reenter

Hello there,

I have two questions where I couldn’t find a solution for a long time and hope the kind people of this forum can help me. I use the basExperience, but my gut tells me to solve this problem I have to create the instances myself.

1. The xr-camera is not in the same position as the main camera when reentering
Like explained here WebXR Experience Helpers | Babylon.js Documentation

(if the ground is not at 0, or if the user starts in a different level)

I applied the following method and it works perfectly (with my code):

this.xr.baseExperience.onInitialXRPoseSetObservable.add((cam) => {
            cam.position = this.camera.position;

Now if you reenter, the camera will be on the floor again. I also tried the reference space methods in the session manager explained here WebXR Session Manager | Babylon.js Documentation
but nothing seemed to happen.
How can I manifest that the xr-camera has always the same position as the main camera and vice versa. (I can’t use a floor because the camera is for a moment just an observer in my room and “hangs” in the air.)

2. Is there a possibility to enter the ‘immersive-xr’ mode automatically?
For instance, when the meshes are all loaded and XR has been instantiated, I can call a function that transfers the user immediately into the XR mode (without clicking the button). Does this exist? Or do I have to automatically click the button for it to happen?

I appreciate any help,
Cheers Tim

Tagging our XR Guru @RaananW :smiley:

A few things -
When exiting XR the XR camera’s position is being copied to the original camera, so this might be the reason why it stops working afterwards. If you know the position in space you want the camera to start at, make sure your original camera is also set at this position.
But I think in your case this is a different issue. when you are setting “cam.position = this.camera.position” you are actually creating a reference for a single position object to both cameras. so every change to one will also influence the other. This could lead to unexpected results. using position.copyFrom(otherPosition); would work better.

Nope :slight_smile:
Not unless you enter from a different XR session. The browser requires a user interaction in order to enter. This is a security and privacy concern for XR scenarios

This makes a lot of sense. So it was my poor coding :smiley: It works now. Thank you @RaananW :slight_smile:

This is also pretty comprehensible. I will try to make it bigger via this.xr.enterExitUI.overlay.style. Thanks @carolhmj @RaananW . You’re the best :smiley: