Two engines, how to return to the first, after interacting with the second?

When loading the page, I create the first engine and scene.
Then I create the second engine and the scene in it in a pop-up window. After closing the window, as I understand it, Babylon JS is in the second engine, and when interacting with the first scene, errors appear. How to return to the first engine?
I hope I was able to explain, I don’t know how to make a playground
Thanks for your help!

Solved the problem with this
BABYLON.EngineStore._LastCreatedScene = scene1
Is that correct or is there another solution?

1 Like

I’m not sure to get your problem but if this works for you I’m fine. That being said, this may mean you are calling new XXX without giving the current scene (this is why by default Babylon will take the latest created one)

Also latest created should be automatically updated when you dispose your secondary scene and engine so make sure to call dispose on these objects

Yes, I did scene2.dispose(); engine2.dispose();
But after that BABYLON.EngineStore.LastCreatedScene returned null

yeah I see that
totally a bug! let me fix that :slight_smile:

Fix scene dispose to restore LastCreatedScene correctly by deltakosh · Pull Request #16067 · BabylonJS/Babylon.js

2 Likes

Thank you!
Another question, how to switch between simultaneously running engines?
Is this ok?
BABYLON.EngineStore._LastCreatedScene = scene1 //active engine 1
else
BABYLON.EngineStore._LastCreatedScene = scene2 //active engine 2

you should never do that :slight_smile:
The lastCreatedScene is only for people who forgets to set the scene parameter when they create an object

If you need to rely on it, it means you are creating mesh, camera, lights or materials without setting the scene parameter and this is bad. Somewhere a kitten may die because of that

3 Likes

This escalated quickly lol I was definitely not ready for it

Yes, I understand. But what if two scenes are running in
two canvases at the same time?

then they are completely separated (not the same engine) so they should never get mixed up