Hi folks!
To allow users to start a game, exit (to a main menu), and restart the game countless times without reloading the page, is there a recommended, robust way of cleaning up and handling Babylon.js’ lifecycle?
For robustness, I was thinking of disposing and recreating Scene every game restart so that I don’t have to manage disposing all the existing Babylon resources for players, weapons, environments, etc… and start from a clean slate. But I’d also like to reuse the assets already loaded instead of reloading them.
I load most of my assets into Babylon’s AssetContainers, then create instances or clones of the meshes inside as players, weapons, etc… are added.
Google’s AI overview says that using AssetContainer allows you to move everything within it from one scene to another scene.
However, Claude says that won’t move everything in the container to the new scene:
Every Babylon item (
Mesh,Material, etc.) has_scenebaked in at constructor time and Babylon never reassigns it.Mesh.clone()/createInstance()bind the new clone tosource.getScene()— i.e. the source’s stale_scene. So clones made from a cached template always bind to the original scene, no matter which scene you’re trying to put them in.scene.addMesh()only pushes to the array; it doesn’t update_scene. Result: cached templates produce clones tied to the disposed scene.
Just curious to hear your thoughts on this
Thank you all!