agentleFS
fetastyfetasty/godot-skills/godot-gdscript/SKILL.md

godot-gdscript

Skill29 starsChanged 6 months agoMITView on GitHub

Godot 4 GDScript code quality: static typing, signal architecture, coroutines, design patterns, performance optimization, and GDScript-specific idioms. Use when writing or reviewing .gd files in Godot 4 projects for: (1) Enforcing static typing standards, (2) Designing signal and node communication patterns, (3) Implementing state machines/command/observer patterns in GDScript, (4) Optimizing GDScript performance, (5) Reviewing GDScript code for anti-patterns.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 3 are distinctive, and 10 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 10

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    ALL variables, parameters, and return types must have explicit type annotations:

    line 18
  2. Very specific:

    Use @onready for typed node references:

    line 32
  3. Very specific:

    Use @export_group and @export_subgroup for inspector organization

    line 46
  4. Distinctive:

    Prefer signals for decoupled communication between nodes

    line 64
  5. Very specific:

    Never connect signals in _process() — connects every frame

    line 65
  6. Very specific:

    Always disconnect in _exit_tree() if node may outlive the connection

    line 66
  7. Very specific:

    Use EventBus autoload for global events, direct signals for parent-child

    line 67
  8. Very specific:

    Never use yield() — that's Godot 3 syntax.

    line 86
  9. Very specific:

    Use duplicate_deep() for nested resources (Godot 4.5+).

    line 116
  10. Distinctive:

    Script backtracing: Call stacks available even in Release builds (4.5+)

    line 137
  11. Very specific:

    Use _physics_process for movement/physics, _process for visuals/UI

    line 146
  12. Very specific:

    Use StringName for frequently compared strings: &"animation_name"

    line 148
  13. Very specific:

    Avoid Array.find() in hot paths — use Dictionary lookups

    line 149

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Godot GDScript Specialist

GDScript 2.0 code quality, patterns, and optimization for Godot 4.6 projects.

Static Typing (Mandatory)

ALL variables, parameters, and return types must have explicit type annotations:

# YES — typed
var health: float = 100.0
var inventory: Array[Item] = []
func take_damage(amount: float, source: Node3D) -> void:
func get_items() -> Array[Item]:

# NO — untyped
var health = 100.0
func take_damage(amount, source):

Use @onready for typed node references:

@onready var health_bar: ProgressBar = %HealthBar
@onready var sprite: Sprite2D = $Visuals/Sprite2D

Enable unsafe_* warnings in project settings to catch untyped code.

File Organization

  • One class_name per file — file name matches class in snake_case
    • player_character.gd → class_name PlayerCharacter
  • Scripts extend the node type they're attached to
  • Use @export_group and @export_subgroup for inspector organization

Signal Architecture

signal health_changed(new_health: float, old_health: float)
signal died(source: Node)

# Modern emit syntax (Godot 4)
health_changed.emit(_current_health, _previous_health)
died.emit(killer)

# Typed connections
health_changed.connect(_on_health_changed)
# One-shot
health_changed.connect(_on_damaged_once, CONNECT_ONE_SHOT)
  • Prefer signals for decoupled communication between nodes
  • Never connect signals in _process() — connects every frame
  • Always disconnect in _exit_tree() if node may outlive the connection
  • Use EventBus autoload for global events, direct signals for parent-child

Coroutines and Async

# Await a signal
await get_tree().create_timer(0.5).timeout

# Await a tween
var tween := create_tween()
tween.tween_property(sprite, "modulate:a", 0.0, 0.3)
await tween.finished

# Await parallel operations
var timer := get_tree().create_timer(1.0)
var tween := create_tween().tween_property(self, "position", target, 1.0)
await timer.timeout  # or await tween.finished

Never use yield() — that's Godot 3 syntax. Use await exclusively.

Design Patterns

State Machine

enum State { IDLE, RUNNING, JUMPING, FALLING, ATTACKING }
var _current_state: State = State.IDLE

func _physics_process(delta: float) -> void:
    match _current_state:
        State.IDLE:
            _process_idle(delta)
        State.RUNNING:
            _process_running(delta)

For complex states, use node-based state machines (each state is a child Node).

Resource Pattern

class_name WeaponData extends Resource
@export var damage: float = 10.0
@export var attack_speed: float = 1.0
@export var weapon_type: WeaponType

Resources are shared by default — use resource.duplicate() for per-instance data. Use duplicate_deep() for nested resources (Godot 4.5+).

Composition Over Inheritance

@onready var health_component: HealthComponent = %HealthComponent
@onready var hitbox_component: HitboxComponent = %HitboxComponent

func _ready() -> void:
    health_component.died.connect(_on_died)
    hitbox_component.hit_received.connect(_on_hit_received)

Maximum inheritance depth: 3 levels after Node base.

Post-4.3 GDScript Features

From references/current-best-practices.md in the godot skill:

  • Variadic arguments (4.5+): func log(prefix: String, values: Variant...) -> void:
  • Abstract classes (4.5+): @abstract class_name BaseEnemy and @abstract func get_pattern()
  • Script backtracing: Call stacks available even in Release builds (4.5+)

Performance

  • Disable _process and _physics_process when not needed:
    set_process(false)
    set_physics_process(false)
  • Use _physics_process for movement/physics, _process for visuals/UI
  • Cache node references in @onready — never get_node() in _process
  • Use StringName for frequently compared strings: &"animation_name"
  • Avoid Array.find() in hot paths — use Dictionary lookups
  • Object pooling for frequently spawned objects (projectiles, particles)
  • Typed arrays (Array[Type]) are faster than untyped arrays
  • Threshold for GDScript → GDExtension: if a function runs >1000 times per frame

Common GDScript Anti-Patterns

  • Untyped variables and functions — disables compiler optimizations
  • Using $NodePath in _process instead of caching with @onready
  • Deep inheritance trees instead of composition
  • Signals for synchronous communication — use direct method calls
  • String comparisons instead of enums or StringName
  • Dictionaries for structured data instead of typed Resources
  • God-class Autoloads that manage everything
  • Editor signal connections — invisible in code, hard to track
  • Using yield() instead of await

Tooling

ripgrep for GDScript: No gdscript type exists. Always use --glob "*.gd" or glob: "*.gd". Using --type gdscript produces a hard error.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.