Issue with creation of WebXRCamera

I’m trying to use the WebXRCamera. I hadn’t luck in finding a working example of the use of WebXRCamera by searching Playgrounds and on Google. I use the following lines to create the WebXRCamera:

const xrSessionManager = new BABYLON.WebXRSessionManager(scene);
const xrCamera = new BABYLON.WebXRCamera("camera", scene, xrSessionManager);

but the code doesn’t work. I should see a sphere, and instead the scene appears void. But, if I use a FreeCamera instead, the scene renders correctly.

I create a minimum, reproducible example at this Playground:

https://www.babylonjs-playground.com/#RU6JWI

Where have I messed in the creation of the WebXRCamera?

Unfortunately I encountered and additional issue: the Playground prints the message createEngine function must return an engine, which I was unable to fix. But outside of the Playground this issue disappears.

If you look at the log, it states:

Uncaught SyntaxError: await is only valid in async function

Does this work? https://www.babylonjs-playground.com/#RU6JWI#1

1 Like

As for the actual issue, maybe @RaananW can help.

1 Like

The XR camera is initialized when you call createDefaultXRExperienceAsync, there is no need to directly create it, unless you want to implement the experience helper yourself (i.e. initialize all needed parts and enter the scene manually). The scene’s initial camera should be a regular non-Vr supported camera (well, any other than the XR camera :slight_smile: ). Arc rotate or free camera will do just fine. Afterwards you have direct access to the XR camera inside the experience helper

1 Like

It worked as you suggested: I took an ordinary camera and then got the xrCamera from xrHelper.

Thanks!

1 Like

I’ve created a Playground which shows how to change position of the WebXRCamera, for future reference:

https://www.babylonjs-playground.com/#BYNTY2