@julien-moreau If I create a Mesh outside of the scene model, is it possible to attach a script to it? I came across the registerScriptInstance method and tried using it, but it didn’t seem to work. Any guidance on this would be highly appreciated.
Here is my code. There are no errors at runtime.
const box = MeshBuilder.CreateBox('abc', { size: 100 });
registerScriptInstance(dynamicMesh, new SceneComponent(box), 'key');
Hi @Zhe_Zhang !
This is a missing feature. I’m on it and I can publish a new version of babylonjs-editor-tools.
I propose:
import { applyScriptOnObject } from "babylonjs-editor-tools";
// A script of your project:
export default class MyScriptClass {
public constructor(
public myObject: Mesh
) {}
public onStart(): void { console.log("hello"); }
public onUpdate(): void { /* ... */ }
}
// Somewhere in the app or another script
const instance = await applyScriptOnObject(targertObject, MyScriptClass);
The function applyScriptOnObject has to be async today because decorators that may be available in the script have to be computed. I’m thinking about an implementation that doesn’t requrire it to be async. Also, it may require as parameter a rootUrlvalue in case decorators have to retrieve files.
What do you think?
Pinging @Soullnik and @yuripourre too in case they have insights 
2 Likes
That would be perfectly fine. 
1 Like