How to add a script to a transform node on runtime in unity toolkit

Hi,

I want to add a script of my own (of type ScriptComponent) on runtime to a transform node.

something like

let characterControllerTrans = this.someTransform.clone("characterController", null);
characterControllerTrans.addComponent<Project.CharacterController>();

Thank you

cc @MackeyK24

Pinging @MackeyK24 again in case they haven’t seen

Do you mean instantiating a configured prefab at runtime or actually constructing up an object from scratch completely at runtime ?

To instantiate a prefab you configured in the Unity Editor:

1... Setup the node and attach any script components
2... Export the selection to create a separate glb to load as an Asset Containers
3... Load the Asset Container at runtime
4... Call the BABYLON.SceneManager.InstantiatePrefabFromContainer

To construct an object from scratch:

BABYLON.SceneManager.RegisterScriptComponent

Example Playground