Hello everybody
I am new to BJS and am struggling understanding the lifecycles of a script attached to a Node.
Let’s say I connect to websockts on the public onStart()
. Where in the code am I suppoded to close the connection when I press the stop button in the preview of the editor?
Is there a lifecycle method like onStop()/onDispose()/onEditorStop()
or something like that?
The socket disconnects only if I run the project in the browser and I close it, but not in the editor.
Could please somebody point me to the right documenatation?
Thank you very much!
Hi @ggcaponetto !
You are right, the editor’s api is missing some functions and I’m adding it for the next release!
For instance, you can use the Babylon.JS API onDisposeObservable
until I add these lifecycle functions. This observable is available in the Node
and Scene
classes. Example:
import { Mesh } from "@babylonjs/core/Meshes/mesh";
export default class MyMeshComponent extends Mesh {
/**
* Called on the node is being initialized.
* This function is called immediatly after the constructor has been called.
*/
public onInitialize(): void {
this.onDisposeObservable.addOnce(() => {
mySockets.dispose();
});
}
}
1 Like
Thank you very much @julien-moreau.
@ggcaponetto editor v4.2.0 has been released introducing onStop method in scripts. This may match your case 
1 Like