Error while changing scenes in babylonjs webxr

Hey guys,

when trying to change the scene from one to another getting this issue which I couldn’t understand, I’m adding snapshot of the issue and the xr init code as well… ps guide me through…

const createXRSession = async (props) => {
    var xr =await scene.createDefaultXRExperienceAsync({
        outputCanvasOptions: {
            canvasOptions: {
                framebufferScaleFactor: 100,
                antialias: true,
            }
        }
    });
    var  xrcamRoot =  new TransformNode("XRCam", scene);
    XRCam =  xr.baseExperience.camera
    xrHelper = await WebXRExperienceHelper.CreateAsync(scene); 
    if(xrHelper.state = WebXRState.NOT_IN_XR)
    {
       const sessionManager = await xrHelper.enterXRAsync("immersive-vr", "local-floor" );
    }
    
    xrcamRoot.scaling = new Vector3(1,1,1);
    XRCam.parent = xrcamRoot;
    xr.baseExperience.onStateChangedObservable.add((state)=>{
        if(state === WebXRState.IN_XR){
            XRCam.position.y = camera.target.y;
        }
    });
   
 }```

Seems like you need to call in this code from a user interaction like a click event to allow it to work.

1 Like

thanks for the heads up it worked