Skip to content

/godot-patterns

Idiomatic Godot 4 GDScript patterns - static typing, scene and node design, signals, resources, autoloads, input, and lifecycle safety. Use when writing or reviewing GDScript, designing scenes, or deciding where game state should live.

From plugin
ecc
306k200 skills72 agents113 commands1 MCP

Claude Code

$ npx -y skills add affaan-m/ECC --skill godot-patterns --agent claude-code

SKILL.md

godot-patterns.SKILL.md
name: godot-patterns
description: Idiomatic Godot 4 GDScript patterns - static typing, scene and node design, signals, resources, autoloads, input, and lifecycle safety. Use when writing or reviewing GDScript, designing scenes, or deciding where game state should live.
origin: ECC

Godot 4 GDScript Patterns

Idiomatic patterns for Godot 4.x projects written in GDScript. Verified against the Godot 4.7 documentation; most guidance applies to every 4.x release.

When to Activate

  • Writing or reviewing `.gd` files
  • Designing a scene tree or deciding which node owns what
  • Choosing between a signal, a direct call, an autoload, or a Resource
  • Debugging "node not found", freed-object, or signal-connection errors
  • Structuring a game so its logic can be tested without running the renderer

Core Principles

1. **Type everything.** Typed GDScript catches bugs at parse time and speeds up the editor. 2. **Call down, signal up.** A parent may call methods on its children. A child announces events with signals and never reaches up to its parent. 3. **Keep game logic out of Nodes where you can.** Plain `RefCounted` or `Resource` classes can be tested headlessly. Nodes should draw and forward input. 4. **Data lives in Resources, not in scripts full of constants.** 5. **Autoloads are global state.** Use as few as you can and treat each one as a public API.

Static Typing

class_name Inventory
extends RefCounted
## A bag of item counts. Pure data and rules: no Node, so tests can run headlessly.

signal item_added(item_id: StringName, new_count: int)  ## typed signal parameters

const MAX_STACK: int = 99           ## typed constant

var _counts: Dictionary[StringName, int] = {}  ## typed Dictionary (Godot 4.4+)


## Adds `amount` of an item and returns how many were actually added.
func add(item_id: StringName, amount: int) -> int:
	var current: int = _counts.get(item_id, 0)
	var added: int = mini(amount, MAX_STACK - current)   # clamp to the stack limit
	if added <= 0:
		return 0
	_counts[item_id] = current + added
	item_added.emit(item_id, _counts[item_id])           # Signal.emit(), not emit_signal()
	return added

Rules of thumb:

  • Annotate parameters and return types (`-> void` included).
  • Use `:=` when the type is obvious from the right-hand side, and an explicit type when it is not.
  • Use typed arrays (`Array[Enemy]`) and, on 4.4+, typed dictionaries.
  • Use `StringName` literals (`&"player"`) for ids and keys that are compared often.
  • Cast with `as` and check the result for `null` before using it.

File Layout and Naming

| Thing | Convention | Example | |-------|-----------|---------| | Files and folders | `snake_case` | `player_controller.gd` | | Classes (`class_name`) | `PascalCase` | `PlayerController` | | Functions, variables | `snake_case` | `take_damage()` | | Private members | leading `_` | `_speed` | | Constants, enum values | `CONSTANT_CASE` | `MAX_LIVES` | | Signals | past-tense `snake_case` | `health_changed` |

Order inside a script (from the official style guide): `class_name`, `extends`, doc comment, signals, enums, constants, `@export` vars, public vars, private vars, `@onready` vars, then methods. Put built-in callbacks (`_init`, `_ready`, `_process`) before your own methods.

Scene and Node Design

Call down, signal up

class_name Player
extends CharacterBody2D
## The player owns a Health child and listens to it. Health knows nothing about Player.

@onready var _health: Health = %Health        # %Name = scene-unique node, survives re-parenting


func _ready() -> void:
	# Listen UP the tree via the child's signal (child -> parent communication).
	_health.died.connect(_on_died)


func _on_died() -> void:
	queue_free()                               # parent decides what death means
class_name Health
extends Node
## A reusable component. It emits events and never touches its parent.

signal died
signal changed(current: int, maximum: int)

@export var maximum: int = 10                  # tweakable per scene in the inspector

var current: int = maximum


func damage(amount: int) -> void:
	current = maxi(current - amount, 0)
	changed.emit(current, maximum)
	if current == 0:
		died.emit()

Wiring siblings without hard paths

Avoid `get_node("../../UI/Label")`. It breaks whenever the tree changes. Prefer, in order:

1. `%UniqueName` for nodes inside the same scene. 2. An `@export var target: Node` assigned in the inspector. 3. A signal that a common ancestor connects. 4. Groups (`add_to_group("enemies")`, `get_tree().get_nodes_in_group("enemies")`) for "all of a kind" queries.

Signals

  • Connect with a `Callable`: `button.pressed.connect(_on_pressed)`.
  • For one-shot reactions use `CONNECT_ONE_SHOT`.
  • Disconnect or `queue_free()` on teardown. A connection to a freed object is cleaned up automatically, but a long-lived emitter holding a Callable to a short-lived object that is still alive keeps it reacting.
  • Bind extra arguments with `.bind()`: `slot.pressed.connect(_on_slot.bind(slot_index))`.
  • Do not use signals for hot per-frame data. Read the value directly.

Resources for Data

class_name WeaponData
extends Resource
## Designer-editable weapon stats stored as a .tres file. No logic beyond small helpers.

@export var display_name: String = ""
@export var damage: int = 1
@export var cooldown_seconds: float = 0.5
@export var icon: Texture2D


## Damage per second, derived so it is never stored twice and cannot drift.
func dps() -> float:
	return damage / cooldown_seconds
  • Share one `.tres` for read-only data. Call `duplicate()` before mutating it per instance, otherwise every user of that file changes together.
  • Use Resources for save data too, but never load a `.tres` or `.res` from an untrusted path: Resources can embed scripts. For user-provided saves use JSON or `ConfigFile`.

Autoloads (Singletons)

Good uses: an event bus, settings, scene-transition manager, save sy

Read more
@affaan-m
Ships withecc

Your agent can write code, but ECC gives it a coordinated engineering system and toolbox: it plans before it builds, verifies changes with tests, reviews its own work from a fresh context, remembers what matters, and turns repeated wins into reusable skills

306k200 skills72 agents1 MCP
Get the whole plugin, auto-invoked

Stars on GitHub

Momentum

stars in total
305.8k
Star history of affaan-m/ECC on GitHub, a chart by star-history.com

Other skills on ecc.

accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

@affaan-m@affaan-mInstall Skill
agent-architecture-audit
Auto-invoked

agent-architecture-aud…

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution,…

@affaan-m@affaan-mInstall Skill
agent-eval
Auto-invoked

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and…

@affaan-m@affaan-mInstall Skill
agent-harness-construction
Auto-invoked

agent-harness-construc…

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when…

@affaan-m@affaan-mInstall Skill
agent-introspection-debugging
Auto-invoked

agent-introspection-de…

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports.…

@affaan-m@affaan-mInstall Skill
agent-security-hardening
Auto-invoked

agent-security-hardeni…

Security hardening guidance for AI agent frameworks that process untrusted content, invoke tools, write workspace files, manage…

@affaan-m@affaan-mInstall Skill

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills2w309k
@mattpocock@mattpocockInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react9d252k
@facebook@facebookInstall Skill
act-on-feedback

act-on-feedback

Act on user feedback attached to the current session. Use when the user submits feedback on the session's changes via the Submit…

vscode9d195k
@microsoft@microsoftInstall Skill

Questions about godot-patterns.

Which coding agents can use godot-patterns?
godot-patterns installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.