attach_script
Attaches a GDScript or C# script to a node in a Godot scene, replacing any previous script and saving automatically. Use after validating the script to ensure it can be instantiated.
Instructions
Attach a GDScript or C# script to a node in a scene. Use after writing and validating it via the validate tool. C# needs the Godot .NET build with the class compiled into the project assembly. Replaces any previous script. Saves automatically. Returns: success with nodePath and scriptPath. Errors if the script can't be instantiated (parse errors, @abstract, or an unbuilt C# class), scriptPath doesn't exist, or nodePath isn't found. Errors while a Godot runtime session is active; stop_project (or detach_project) clears it.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodePath | Yes | Node path from scene root (e.g. "root/Player") | |
| scenePath | Yes | Scene file path relative to the project | |
| scriptPath | Yes | Path to the script file relative to the project (e.g. "scripts/player.gd" or "scripts/Player.cs"). A .cs file needs the Godot .NET build and its class compiled into the project assembly (dotnet build). | |
| projectPath | Yes | Path to the Godot project directory |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| success | No | ||
| nodePath | No | ||
| scriptPath | No |