I need a custom parameters accessible from Editor

I need a custom parameters accessible from the editor but exportScript doesn’t work
this is my code :

import { Node, Color4,Scene } from "@babylonjs/core";

export default class MyScript extends Node {
    public blackColor = new Color4(0, 0, 0, 1);

    protected constructor() { }


    public onInitialize(): void {
        // ...
    }


    public onStart(): void {
        // ...
    }


    public onUpdate(): void {
        // ...
    }


    public onMessage(name: string, data: any, sender: any): void {
        switch (name) {
            case "myMessage":
                // Do something...
                break;
        }
    }

    
}

exportScript(
    MyScript, 

    { blackColor: new Color4(0,0,0,1) }
);

in the vscode, the exportScript function has a error “Cannot find name 'exportScript '”

editor version : v4.0.4

pinging @julien-moreau

1 Like

Hi @Reza_B !

The way to export scripts and custom properties has changed from v3 to v4: the version 4 is now using decorators. More informations here: Editor/attaching-scripts.md at master · BabylonJS/Editor · GitHub

Your script should become something like:

import { Node, Color4,Scene } from "@babylonjs/core";

// The path can change according to where your script is located
import { visibleInInspector } from "../decorators.ts";

export default class MyScript extends Node {
    // Decorate the property using @visibleInInspector
    @visibleInInspector("Color4", "Black Color", new Color4(0, 0, 0, 1))
    public blackColor = new Color4(0, 0, 0, 1);

    protected constructor() { }


    public onInitialize(): void {
        // ...
    }


    public onStart(): void {
        // ...
    }


    public onUpdate(): void {
        // ...
    }


    public onMessage(name: string, data: any, sender: any): void {
        switch (name) {
            case "myMessage":
                // Do something...
                break;
        }
    }
}

Once your script is saved, the Editor will update its interface in the “Inspector” panel to show you the new field that can be edited.

2 Likes

Hi @Reza_B just checking in, were you able to get your custom parameters?