connect_signal
Add signal connections between nodes in Godot .tscn scene files to enable event-driven communication and game logic.
Instructions
Add a new signal connection between nodes in a .tscn scene file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scene | Yes | Path to the .tscn file | |
| source | Yes | Source node name (emitter) | |
| signal | Yes | Signal name | |
| target | Yes | Target node name (receiver) | |
| method | Yes | Handler method name on the target | |
| flags | No | Connection flags (default: 0) | |
| expectedHash | No | Expected content hash for stale-edit prevention |
Implementation Reference
- src/tools/scene-edit-tools.ts:381-454 (handler)The handler function for 'connect_signal' which validates the scene and nodes, checks for duplicates, and appends the new signal connection.
handler: async (ctx) => { const { scene: scenePath, source: sourceNode, signal: signalName, target: targetNode, method, flags = 0, expectedHash, } = ctx.args; validatePath(scenePath); return withFileLock(scenePath, async () => { try { const { source, scene } = await readAndParse(scenePath); const hashErr = hashCheck(source, expectedHash); if (hashErr) return makeTextResponse({ error: hashErr, data: null }); // Validate source and target nodes exist (by node name in connections) let sourceExists = false; let targetExists = false; for (const [, node] of scene.nodes) { if (node.name === sourceNode || node.nodePath === sourceNode) sourceExists = true; if (node.name === targetNode || node.nodePath === targetNode || targetNode === ".") targetExists = true; } if (!sourceExists) { return makeTextResponse({ error: `Source node not found: ${sourceNode}`, data: null, }); } if (!targetExists) { return makeTextResponse({ error: `Target node not found: ${targetNode}`, data: null, }); } // Check for duplicate const duplicate = scene.signalConnections.find( (c) => c.signalName === signalName && c.sourceNode === sourceNode && c.targetNode === targetNode && c.targetMethod === method, ); if (duplicate) { return makeTextResponse({ error: "Connection already exists", data: null, }); } scene.signalConnections.push({ sourceScene: scenePath, sourceNode, signalName, targetNode, targetMethod: method, targetScript: null, targetMethodLine: null, connectionFlags: flags, rawSpan: null, }); await writeAndEmit(scenePath, scene, eventBus, ctx.signal); return makeTextResponse({ data: { signal: signalName, from: sourceNode, to: targetNode, - The schema defining the input arguments for 'connect_signal', including scene, source node, signal, target node, method, and flags.
schema: { scene: z.string().describe("Path to the .tscn file"), source: z.string().describe("Source node name (emitter)"), signal: z.string().describe("Signal name"), target: z.string().describe("Target node name (receiver)"), method: z.string().describe("Handler method name on the target"), flags: z.number().optional().default(0).describe("Connection flags (default: 0)"), expectedHash: z .string() .optional() .describe("Expected content hash for stale-edit prevention"), }, - src/tools/scene-edit-tools.ts:366-366 (registration)The registration entry for the 'connect_signal' tool.
{