attach_script
Attach a GDScript or C# script to a scene node, replacing its existing script and saving automatically. Validate the script first to avoid instantiation errors.
Instructions
Attach a GDScript or C# script to a node in a scene, replacing any script it had. Check the script with the validate tool first. C# needs the Godot .NET build with the class compiled into the project assembly. Saves automatically. Returns: nodePath and scriptPath. Errors if the script cannot be instantiated (parse errors, @abstract, or an unbuilt C# class), or if scriptPath or nodePath does not exist. Errors while a runtime session is live on this project.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"projectPath": "<projectPath>",
"scenePath": "<scenePath>",
"nodePath": "<nodePath>",
"scriptPath": "<scriptPath>"
},
"name": "attach_script"
}
}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 |
|---|---|---|---|
| nodePath | Yes | Path from the scene root in "root/..." form, read from the node. | |
| warnings | No | ||
| scriptPath | Yes | Project-relative path of the script that was attached. |