godot-gdscript-patterns
Use when writing Godot 4 GDScript - static typing everywhere, scene composition with component nodes, call down/signal up, @onready caching, Resources as data…
от makifbaysal★ 123 звезды на GitHub
Установить godot-gdscript-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Godot GDScript Patterns
Overview
Godot's building blocks are nodes composed into scenes, signals between them, and Resources for data. GDScript is dynamic by default, which hides typos until runtime and costs speed; typed GDScript catches them at parse time and runs faster. The common failure modes are untyped code, get_node chains reaching up the tree, logic in Resources, and autoloads holding everything.
Core principle: Type everything, compose scenes from small nodes, call down and signal up, keep data in Resources and rules in plain classes.
Type everything
# ❌ untyped: typos and wrong types surface only when this line runs
var speed = 200
func take_damage(amount):
health -= amount
# ✅ typed: checked when the script parses, faster at runtime
class_name Player extends CharacterBody2D
signal health_changed(current: int, maximum: int)
signal died
@export var definition: PlayerDefinition
@onready var _sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var _hurtbox: Area2D = %Hurtbox
var health: int
func _ready() -> void:
health = definition.max_health
func take_damage(amount: int) -> void:
health = maxi(0, health - amount)
health_changed.emit(health, definition.max_health)
if health == 0:
died.emit()
Turn on Project Settings → Debug → GDScript → untyped_declaration (and unsafe_* warnings) as warnings or errors if the repository has not yet. Typed arrays and dictionaries (Array[Enemy], Dictionary[StringName, int] in 4.4+) everywhere a collection has one element type.
Composition with component nodes
Build behaviour from small reusable child scenes rather than deep inheritance:
Enemy (CharacterBody2D) enemy.gd: wires components, no rules of its own
├── HealthComponent (Node) health_component.gd: health, damage(), signal died
├── HitboxComponent (Area2D) deals damage on overlap
├── HurtboxComponent (Area2D) forwards hits to HealthComponent
└── StateMachine (Node) child state nodes: Idle, Chase, Attack
Each component exports its dependencies (@export var health: HealthComponent) so the scene wires them in the inspector, and each is testable alone.
Call down, signal up
# ❌ reaching up and across the tree: breaks when the scene is reused or rearranged
func _on_hit() -> void:
get_parent().get_parent().get_node("UI/HUD").update_health(health)
# ✅ the child emits; whoever owns both connects them
# in level.gd:
func _ready() -> void:
player.health_changed.connect(hud.show_health)
- Parents call methods on children they own; children announce events with signals.
- Connect in code with Callables (
button.pressed.connect(_on_start_pressed)) or in the editor — follow the repository. @onready(or%UniqueNamefor unique-in-owner nodes) caches node references once; neverget_node()or$Pathinside_process.
Resources: data, duplicated per instance
class_name PlayerDefinition extends Resource
@export var max_health: int = 100
@export var move_speed: float = 180.0
@export var dash_curve: Curve
- Resources hold data, not behaviour (no gameplay logic, no node references).
- A loaded
.tresis shared by everyone who loads it. Runtime state goes on the node, ordefinition.duplicate()per instance, orresource_local_to_scenefor sub-resources edited per scene. - Never load user-provided
.tres/.resfiles: they can carry scripts (game-save-and-persistence).
Autoloads sparingly
Autoloads are global singletons. Acceptable for services: scene loading, save, audio, settings, an event bus for genuinely global events. Not for the current level's state, the player's health or anything a test needs to reset. A level's data belongs to the level scene.
State machines
Small: an enum and a match. Larger: a StateMachine node with one child node per state (enter(), exit(), physics_update(delta), handle_input(event)), transitions requested by name, and the legal transitions tested (game-state-machines-and-ai).
enum State { IDLE, CHASE, ATTACK }
var _state := State.IDLE
func _physics_process(delta: float) -> void:
match _state:
State.IDLE:
if _target_in_range(definition.aggro_range): _change(State.CHASE)
State.CHASE:
_chase(delta)
if _target_in_range(definition.attack_range): _change(State.ATTACK)
State.ATTACK:
pass
Physics, processing and pooling
CharacterBody2D/3D: setvelocity, callmove_and_slide()in_physics_process(delta).RigidBody: forces/impulses, or_integrate_forces(state)for direct control — never setpositionon it every frame.- Turn off what is idle:
set_process(false)/set_physics_process(false),process_mode = PROCESS_MODE_DISABLED,VisibleOnScreenEnabler2D/3Dfor off-screen enemies. - Pool frequent spawns (bullets, hit effects): pre-instantiate, hide and disable processing on re
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл godot-gdscript-patterns?
Use when writing Godot 4 GDScript - static typing everywhere, scene composition with component nodes, call down/signal up, @onready caching, Resources as data duplicated per instance, autoloads only for services, state machines, pooling, physics in _physics_process, and threaded loading.
Как установить скилл godot-gdscript-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл godot-gdscript-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…