So I’ve been using SceneLoader.Append to change between scenes for a project in the babylon.js editor 4.0.0-beta.7, and the script attached to a cube mesh in the scene is still calling onUpdate() despite calling dispose() before the scene change. (still printing to console from onUpdate)
I wrote a test script attached to the cube to test it
export default class TestDispose extends Node {
private constructor() { }
public onInitialize(): void {}
public onStart(): void {
this.getScene.meshes.forEach((value, index, array> {Logger.Log("Mesh Name: " + value.name);}SceneLoader.Append(“…/…/scenes/theOtherScene/”, “scene.babylon”, this.getScene(), (scene)=>{
var scripts = { “src/scenes/theOtherScene/foo.ts” : require(“…/theOtherScene/foo.ts”),}
attachScripts(scripts, scene);
scene.meshes.forEach((value, index, array> {Logger.Log("Mesh Name: " + value.name);})
});//Remove meshes
for (var i = 0; i < this.getScene().meshes.length; ++i){
this.getScene().meshes[i].dispose();
–i;
} //remove meshes for
} //onStartpublic onUpdate(): void {
Logger.Log(“I’m alive”);
}}//TestDispose
Printing out the list of meshes in the scene before and after the scene change also shows that the cube is no longer in the getScene().meshes, but the script attached to it continues to call onUpdate, printing out “I’m alive”.
I’m not sure if there’s a way to explicitly remove and destroy a script, or if there’s more to disposing the mesh to remove the script. I may be in over my head, as I’m not familiar with how garbage collection works in Typescript/Javascript, so I’m not sure how to proceed from here.
Is there a method provided by the editor to explicitly detach or destroy scripts already attached? Do I just need to delete the object generated by the script?