Custom VisualScript nodes
Godot 4.0 will remove VisualScript from core entirely. As a result, creating new projects using visual scripting in Godot is not recommended. Future Godot 4.x releases may have VisualScript reimplemented as an extension.
While Godot 3.x will keep VisualScript supported, we recommend instead, especially if you intend to migrate your project to Godot 4.
Custom nodes are written in GDScript and can then be used in VisualScript. This is useful for offloading complex code to GDScript and reusing it.
Create a new script that extends and put a keyword at the top. This is needed for the script to run in the editor.
The most important part of a custom node is the _step
function. The logic of the node is defined there.
The parameter holds the value of the input ports.
The outputs
parameter is an array where the indices represent the output port ids. It can be modified to set the values of the output ports.
start_mode
can be checked to see if it is the first time _step
is called.
If you want to throw an error, for example if the input types are incorrect, you can return the error message as a string. When everything goes right, return the id of the sequence port which should be called next. If your custom node doesn’t have any, just return 0.
Example:
Using a custom node
To use the script, add a CustomNode
, select it and drag your custom node script into the script
property shown in the inspector.