Hey everyone,
I recently updated babylonjs from 4.0.0-alpha8 to 4.0.3
I have a 2 scene style game when you can go back and forth between the two. Now when i go between the two i get this error “Cannot set property ‘_sceneRootNodesIndex’ of undefined”
It could be that my logic for cleaning up the old scene is slightly off, but im wondering if something im not seeing could be causing this. This seemed to work fine in the alpha build i was using.
I get this when i try to console log scene.rootNodes right before the error
ok i think you fixed the playground at some point…
Thanks
I have not been able to reproduce the bug
Here is as close as i could get, to what i do in my scene.
So i went back to mine, and started debugging again. This bug seems to only happen when i dispose of my main game scene. Even if i dont switch scenes. So im really confused at what could be happening. Since i stop rendering the scene then i try disposing the scene, but get that error.
“Cannot set property ‘_sceneRootNodesIndex’ of undefined”
So far my only hunches are that it could be something to do with using assets loaded from another scene. Like in this post:
any ideas on how i should go about diagnosing what the problem could be?
Ive console logged all the way and end up getting the error on the scene.dispose(), but that works in the playground. So maybe its something im doing to my scene before i dispose? Im not sure… Back to debugging
babylon.js:16 Uncaught (in promise) TypeError: Cannot set property ‘_sceneRootNodesIndex’ of undefined
at t.e.removeFromSceneRootNodes (babylon.js:16)
at t.e.dispose (babylon.js:16)
at t.dispose (babylon.js:16)
at t.dispose (babylon.js:16)
at PlayScene.destroy (PlayScene.ts:740)
at PlayScene.leaveGameScene (PlayScene.ts:732)
at eventDispatcher.ts:66
at Array.forEach ()
at EventDispatcher.dispatch (eventDispatcher.ts:65)
at Container. (container.ts:94)
at step (gameadapter.js:31)
at Object.next (gameadapter.js:12)
at gameadapter.js:6
at new Promise ()
at __awaiter (gameadapter.js:2)
at Object.onRestart (container.ts:89)
at GameOverComponent. (gameOverComponent.ts:63)
at step (gameadapter.js:31)
at Object.next (gameadapter.js:12)
at gameadapter.js:6
at new Promise ()
at __awaiter (gameadapter.js:2)
at Object.onRestart (gameOverComponent.ts:61)
at HTMLDivElement. (actionsComponent.ts:35)
Woot! You cannot change the scene of a mesh. There will be thousands of problems if you do that
That is mostly why we introduced the asset container so you can have groups of active/inactive meshes inside a scene: https://doc.babylonjs.com/how_to/how_to_use_assetcontainer
As a rule of thumb, you should never use anything starting with _
You should not change scene actually if you share meshes.
Do you mean i should only use one scene, then use assets containters as “scene” with all my assets in them ? Then use the asset container to add in a whole “scene” and remove a whole “scene”. Like just adding in whole sets(“scenes”) of meshes and other assets?
Or just dont switch the scene of a mesh?
Use the assetContainer to load the file then just call the file from the asset container when i need it?
but assetContainer needs a scene, so that doesnt seem right…