Problem in XR, entering from a canvas with a main scene and a viewport one over it

I’m new to babylonjs and I am working on an app where I want to show a viewCube in a viewport scene over the main scene on the “desktop” side of the application, and allow the user to enter XR to view the main scene. I quickly made a litte playground to give you an idea of the initial state of what I have in the app :

In that context, when I enter in XR, it seems to be bugged (teleportation lines are not showing and sometimes it can crash after a few seconds) but if I remove the viewport scene, all works fine in XR.

I tried to fix it for a while now and I can’t figure out how to make XR work fine from this configuration.
I already tried some things when entering XR like stopping to render the viewport scene or disposing it.
I also tried other methods like using another canvas or a layer mask but without success (and I guess that the viewport approach seems to be better for a viewCube according to what I saw in the forum so far)

I’m probably missing some knowledge about it as I still discover the framework.
Can someone help me to clarify it and make it work ?

PS: i’m french so my english can be bad sry :sweat_smile:

The issue here is the multi-scene scenario. XR picks the last scene created (if not provided explicitly) and uses it to render the lines of the teleportation path, but it should actually use the scene of the session manager that created it.

This is a quick solution:

Playground with viewPort XR bug | Babylon.js Playground

Until I fix it in code :slight_smile:

1 Like

Thanks a lot for the quick answer. It seems to work fine with your solution :slightly_smiling_face:

If it’s not too much to ask, can you tell me if this viewport scene can cause others problems later in the XR environment or in the transition between the two environments ?
I plan to have different UIs between the “desktop” and the XR environment and to allow switching between both easily, using the onStateChangedObservable method of the default xr experience to activate/deactivate the correct UI on the screen when the transition is done.

Is it the right way to do so ?

Thanks again

There should be no issue whatsoever! :slight_smile:

And if there is we will need to take care of it. XR will technically take the transformation of your main camera when entering the session and will update the main camera with its transformation when exiting XR. otherwise there is lieetle to no interaction between the two view-cameras (and viewports).

Perfect ! :slight_smile:

Thanks a lot again for your help

1 Like