Can't enter XR any thoughts why?

I’m having a problem with entering xr. I’ve created a simple scene and added the default xr in my scene and a button that when clicked user should enter xr but it’s not working. what am I doing wrong here, any thoughts?

here is my scene: https://playground.babylonjs.com/#ZAHFTQ#9

Hey @Paz2012,

I was looking at your code it looks like the issue may be related to your createXR function. If I’m understanding correctly, you were trying to go for was to save a WebXRExperienceHelper so that you could call enterXRAsync. The issue is that when the timeout completes in createXR, it will still return a Promise object, rather than just returning a WebXRDefaultExperience object. You might want to try using .then():

    setTimeout(() => {
        scene.createDefaultXRExperienceAsync({disableTeleportation: true}).then(value => {
            helper = value;
        });
    }, 250);

Depending on how tied you are to setTimeout, you can always just omit that entirely.

That brings me to my next finding. Because your helper variable is of the type WebXRDefaultExperience, you won’t have access to it unless you go into the baseExperience variable. Inside of your enterXR function, you can simply add baseExperience and that function should be accessible:

await helper.baseExperience.enterXRAsync("immersive-vr", "local-floor")

You could also change your createXR function to look something like this, if you don’t want to touch your enterXR function:

async function createXR(scene: BABYLON.Scene) {   
    await scene.createDefaultXRExperienceAsync({disableTeleportation: true}).then(value => {
        helper = value.baseExperience;
    });
}

This is just a way to do it but hopefully, I’ve at least helped a bit.