[Editor 4.0.0-beta.7] Script still running after attached mesh disposed?

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){
} //remove meshes for
} //onStart

public onUpdate(): void {
Logger.Log(“I’m alive”);


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?

Pinging @julien-moreau

Hey @vUdevU! Nice catch!! Thanks for reporting!
Just fixed and fix is available on branch release/4.0.0 (here: GitHub - BabylonJS/Editor at release/4.0.0). Can you build the Editor yourself or do you need a release ASAP?

1 Like

I would greatly appreciate a release! I haven’t tried building the editor myself yet, but I can work on some other parts of my project while waiting for a release. Thanks!

Hey @vUdevU, just released!
You’ll be notified by the Editor or you can simply download the update here: BabylonJS Editor v4.0.0 beta · BabylonJS/Editor Wiki · GitHub :slight_smile:

Don’t hesitate if you encouter any other bug or want to suggest some improvements / feature requests :slight_smile:

1 Like

Thank you!! And thank you for your quick responses and fixes!