Skip to content

3.5 ‐ 06 Tooled scripts

WhyTry313 edited this page Sep 21, 2023 · 4 revisions

Description

Tooled scripts are executed in the editor, making it useful to both debug and create elements in the a scene without having to run the entire scene or game. Applications can go from a simple print of variable to a whole editor extension, are convenient for designing interfaces, drawing trajectories and simulate results based on editor values changes.


Syntax

godot.set_script_tooled(Class:ClassName, bool);


How to use it with examples

In GDScript, this keyword is used at the beginning of the script

@tool
var myvar = 10
export var myEditorValue = 20

func _ready():
    print("This will print on scene load")

With JavaScript, it's a godot method that registers the class as tooled with godot.set_script_tooled, meaning you can have code before and after registering the class

export default class MyClass extends godot.Node {
    constructor() {
        this.myvar = 10;
    }
    _ready() {
        console.log("This will print on scene load");
    }
}

godot.set_script_tooled(MyClass, true);
godot.register_property(MyClass, "myEditorValue", 20);

Hot-reload is not supported (for now)

Unfortunately the hot-reload feature is not supported, any tooled script must be reloaded by clicking the Scene > Reload saved scene button. The script will still work as the last loaded version but any changes on the tooled script requires a refreshed scene to apply changes.