
godot-state-machine-advanced
Expert blueprint for hierarchical finite state machines (HSM) and pushdown automata for complex AI/character behaviors. Covers state stacks, sub-states, transition validation, and state context passing. Use when basic FSMs are insufficient OR implementing layered AI. Keywords state machine, HSM, hierarchical, pushdown automata, state stack, FSM, AI behavior.
- Installs
- 491
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/thedivergentai/game-dev-agentic-skills --skill godot-state-machine-advanced- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads godot-state-machine-advanced automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Available Scripts
hsm_hierarchical_base.gd
Advanced HSM base delegator for propagating physics and input to sub-states.
hsm_pushdown_stack.gd
Professional Pushdown Automata for interruptive state (Pause/Menu) stacking.
hsm_state_context.gd
Decoupled context object pattern for passing persistent data between states.
hsm_transition_guard.gd
Expert transition validation logic to prevent illegal state changes.
hsm_animation_syncer.gd
Automated Logic-to-AnimationTree syncing with state-based travel logic.
hsm_concurrent_logic.gd
Orchestration for parallel state machines (e.g., Move + Attack).
hsm_resource_state_loader.gd
Data-driven state definition using custom Godot Resources (.tres).
hsm_reentry_aware_state.gd
Handling resume-from-stack logic vs fresh entry events.
hsm_state_history_logger.gd
Debug ring-buffer for tracking state transition history and stack depth.
hsm_state_timer_component.gd
Auto-transition component for finite states like Stun or Dash.
MANDATORY: For hierarchy / pushdown / guards read hsm_hierarchical_base.gd, hsm_pushdown_stack.gd, hsm_transition_guard.gd (plus hsm_logic_state.gd for leaf behaviors).
Decision Tree — Which Machine?
| Need | Choose | MANDATORY scripts |
|---|---|---|
| Few exclusive states, no nesting | Flat FSM | hsm_logic_state.gd + thin parent |
| Nested sub-states (Move/Air/Attack children) | HSM | hsm_hierarchical_base.gd |
| Interrupt overlays (stun/menu/dialogue) then resume | Pushdown | hsm_pushdown_stack.gd + hsm_reentry_aware_state.gd |
| Parallel concerns (locomotion + weapon) | Concurrent | hsm_concurrent_logic.gd |
| Pick best action by score each tick | Utility cost polling | Expert pattern §3 + hsm_transition_guard.gd |
NEVER Do (Expert State Rules)
Hierarchy & Delegation
- NEVER forget to propagate physics/input to children — In an HSM, failing to call
child.physics_update()from the parent's_physics_processorphans child logic. - NEVER use deep nesting (>3 levels) — Extreme hierarchy creates "State Spaghetti." If logic is that complex, consider a Behavior Tree or Utility AI.
Transitions & Lifecycle
- NEVER call enter() without a preceding exit() — Skipping exit logic leaves timers, tweens, or audio loops running in the background, causing resource leaks.
- NEVER modify state during a transition frame — Re-entrant
transition_to()calls insideenter()cause recursion crashes. Usecall_deferredif immediate sub-transitioning is required. - NEVER hardcode state names as strings — Typos like
transition_to("Idel")are silent killers. Useclass_namebased checks OR Constants.
Architecture & Context
- NEVER use global singletons for state data — Coupling states to
GameManager.player_healthmakes them non-reusable. Pass aContextobject. - NEVER push states indefinitely — In a Pushdown Automaton, every
push_stateMUST have a retirement plan (pop_state) to avoid stack overflow. - NEVER assume state re-entry is always a fresh start — Resuming from a stack pop should often bypass "Entry SFX/VFX"; use re-entry flags.
Implementation — Scripts Are Source of Truth
Do NOT copy inline HierarchicalState / push_state samples. Prior body double-
exit()ed and ignored resume messages.
MANDATORY route:
- Hierarchy / physics-input forward: hsm_hierarchical_base.gd
- Push / pop with
enter({"is_resume": true}): hsm_pushdown_stack.gd - Illegal transition blocking: hsm_transition_guard.gd
- Context payload: hsm_state_context.gd
Pushdown contract (from script — single exit, resume msg):
# See hsm_pushdown_stack.gd — do not reimplement
func push_state(state_path: String, msg: Dictionary = {}) -> void: ...
func pop_state() -> void:
# old.exit(); stack.back().enter({"is_resume": true})
pass
Expert State Machine Patterns
1. HSM Visualizer (Debug Tool)
Use a specialized Control node with _draw() to visualize the current state stack/hierarchy in the viewport for immediate debugging [3, 11].
class_name HSMVisualizer extends Control
@export var state_machine: Node
func _draw() -> void:
var font := ThemeDB.fallback_font
var pos := Vector2(20, 20)
# Recursively draw active state names...
draw_string(font, pos, "Active: " + state_machine.current_state.name)
2. State-Based Audio (Decoupled)
Avoid hardcoding audio.play() inside state enter() methods. Use a syncer that listens to state_changed and maps state names to AudioStream resources [12, 13].
class_name StateAudioSyncer extends Node
@export var state_machine: Node
@export var audio_map: Dictionary # { "Jump": preload("jump.wav") }
func _ready() -> void:
state_machine.state_changed.connect(_on_state_changed)
func _on_state_changed(_old, new_state: Node):
if audio_map.has(new_state.name):
$AudioPlayer.stream = audio_map[new_state.name]
$AudioPlayer.play()
3. Transition Cost (Utility AI)
Enable states to evaluate their own "weight" based on context. The StateMachine polls sibling costs and transitions to the lowest-cost behavior [17, 18].
# CostState.gd (Base)
func get_cost(context: Dictionary) -> float:
return 10.0 # Default weight
# UtilityStateMachine.gd
func _physics_process(_d: float) -> void:
var best_state: Node = current_state
var low_cost: float = INF
for child in get_children():
var cost = child.get_cost(context)
if cost < low_cost:
low_cost = cost
best_state = child
if best_state != current_state:
transition_to(best_state.name)
Deep recipes (on demand)
LLM-ignorance rule: if a general agent would not know it before reading, it lives here or in
scripts/— never delete, only move.
| Topic | Reference |
|---|---|
| State contract + routing | hsm-implementation-cookbook.md |
Reference
Progressive disclosure: open Official Documentation links only when researching a specific API; load Related Skills when routing to a peer domain — do not preload the whole lattice.
Official Documentation
- Using signals — Drive
state_changed/ transition fan-out so listeners (anim, audio, AI) stay decoupled from enter/exit bodies. - Scene organization — Child-node state ownership and signal-up / call-down so the machine orchestrates without sibling hard-coupling.
- What are Godot classes — Prefer composed state nodes +
class_nameover deep inheritance trees for layered AI behaviors. - Idle and Physics Processing — Why HSMs must forward
_physics_process/_processinto the active child (or hierarchy) every tick. - Using SceneTree —
call_deferredtransitions avoid re-entranttransition_to()crashes insideenter(). - Godot notifications — Safe wiring timing for initial
enter()relative to_readyand parent caches. - Resources — Data-driven state definitions (
.tres) for modular AI without baking scripts into every actor. - Using AnimationTree — Logic-to-AnimationTree travel when gameplay HSM states map to blend/state-machine graphs.
- AnimationNodeStateMachinePlayback —
travel()/start()APIs used by animation syncers tied to HSM state names. - Node — Child lookup, process modes, and lifecycle hooks state nodes inherit as scene-tree citizens.
- InputEvent — Typed events parents forward into
handle_inputon the active state. - Timer — Finite-duration states (stun, dash) via one-shot timers that emit transition signals.
Related Skills
Prerequisites
- godot-project-foundations — Scene ownership and project layout conventions every HSM root and child state scene assumes.
- godot-gdscript-mastery — class_name, typed Dictionaries/payloads, and Callables needed for guards, deferred transitions, and context objects.
- godot-signal-architecture — Signal-up transition events without circular graphs where states emit and also listen to themselves.
Complements
- godot-composition — Drop HSM / VSM as a StateComponent under a composition root instead of bloating the actor script.
- godot-input-handling — Sense-layer sampling; states receive directions/actions via handle_input rather than polling globals.
- godot-characterbody-2d — Locomotion states call move_and_slide / velocity APIs on the actor passed through context.
- godot-animation-tree-mastery — Blend trees and AnimationNodeStateMachine graphs that HSM syncers travel into by state name.
- godot-resource-data-patterns — Tunable state Resources (speeds, stun durations, AI weights) separate from runtime Node lifecycle.
- godot-2d-animation — Sprite / AnimationPlayer presentation when a lighter sync path than a full AnimationTree is enough.
Downstream / consumers
- godot-combat-system — Hit-stun, attack windup, and death stacks are classic pushdown / HSM consumers on fighters.
- godot-ability-system — Cast, channel, and cooldown phases map cleanly to guarded transitions and timed states.
- godot-turn-system — Turn phases and interrupt stacks reuse pushdown / concurrent machine orchestration patterns.
- godot-dialogue-system — Cutscene and dialogue overlays push over gameplay states and must pop without losing context.
Master
- godot-master — Library router and mirrored module entry; open when discovering which Domain Skill owns a cross-cutting architecture concern.
FAQ
What does the godot-state-machine-advanced skill do?
Expert blueprint for hierarchical finite state machines (HSM) and pushdown automata for complex AI/character behaviors. Covers state stacks, sub-states, transition validation, and state context passing. Use when basic FSMs are insufficient OR implementing layered AI. Keywords state machine, HSM, hierarchical, pushdown automata, state stack, FSM, AI behavior.
How do I install godot-state-machine-advanced?
Run npx skills add https://github.com/thedivergentai/game-dev-agentic-skills --skill godot-state-machine-advanced in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/godot-state-machine-advanced/ (personal) or .claude/skills/godot-state-machine-advanced/ (project).
Which AI agents can use godot-state-machine-advanced?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is godot-state-machine-advanced safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains godot-state-machine-advanced?
It is published by thedivergentai in thedivergentai/game-dev-agentic-skills. It has 491 recorded installs.
More from thedivergentai/game-dev-agentic-skills
godot-master
thedivergentai/game-dev-agentic-skills
Consolidated expert library for professional Godot 4.7+ game and application development. Orchestrates 92 Domain Skills through architectural workflows, anti-pattern catalogs, performance budgets, and Server API patterns. Use when: (1) starting a new Godot project, (2) designing game or app architecture, (3) building entity/component systems, (4) debugging performance or physics issues, (5) choosing between 2D/3D approaches, (6) implementing multiplayer, (7) optimizing draw calls or script time, (8) porting between platforms, (9) migrating from 4.6 to 4.7. Primary entry point for ALL Godot development tasks. Keywords: Godot 4.7, AreaLight3D, HDR, Asset Store, godot-master.
godot-shaders-basics
thedivergentai/game-dev-agentic-skills
Expert Godot shader patterns for batch-safe hitflash, alpha-scissor foliage/dissolve, screenspace postFX, depth reconstruction, triplanar, and instance uniforms — not first-shader tutorials. Trigger on draw-call batching breaks, discard vs depth-prepass, foliage shadows, post-process quads, or world-position FX. Keywords: instance uniform, ALPHASCISSOR, hintscreentexture, hintdepthtexture, global uniform, sampler2DArray, canvasitem, spatial, post-processing.
godot-2d-animation
thedivergentai/game-dev-agentic-skills
Expert patterns for 2D animation in Godot using AnimatedSprite2D and skeletal cutout rigs. Use when implementing sprite frame animations, procedural animation (squash/stretch), cutout bone hierarchies, or frame-perfect timing systems. Trigger keywords: AnimatedSprite2D, SpriteFrames, animationfinished, animationlooped, framechanged, frameprogress, setframeandprogress, cutout animation, skeletal 2D, Bone2D, procedural animation, animation state machine, advance(0).
godot-ui-theming
thedivergentai/game-dev-agentic-skills
Expert blueprint for UI themes using Theme resources, StyleBoxes, custom fonts, and theme overrides for consistent visual styling. Covers StyleBoxFlat/Texture, theme inheritance, dynamic theme switching, and font variations. Use when implementing consistent UI styling OR supporting multiple themes. Keywords Theme, StyleBox, StyleBoxFlat, addthemeoverride, font, theme inheritance, dark mode.
godot-gdscript-mastery
thedivergentai/game-dev-agentic-skills
Expert GDScript landmine guidance: static typing opcodes, signal-up/call-down, %UniqueName/@onready lifecycle, Callable bind/unbind, await sequences, typed collections, and safe Dictionary iteration. Use for code review, refactoring hot paths, or project standards. Trigger keywords: statictyping, signalarchitecture, uniquenodes, @onready, classname, signalupcalldown, Callable.bind, typedcollections, awaitsequence.
godot-particles
thedivergentai/game-dev-agentic-skills
Expert blueprint for GPU particle systems (explosions, magic effects, weather, trails) using GPUParticles2D/3D, ParticleProcessMaterial, gradients, sub-emitters, and custom shaders. Use when creating VFX, environmental effects, or visual feedback. Keywords GPUParticles2D, ParticleProcessMaterial, emissionshape, colorramp, subemitter, oneshot.
Popular ai & agents skills
google-agents-cli-publish
google/agents-cli
This skill should be used when the user wants to "publish an agent", "publish my ADK agent", "register an agent with Gemini", "publish to Gemini" (formerly Gemini Enterprise), or needs guidance on the agents-cli publish gemini command. Also use when the user wants to "manage agents in Agent Registry", "list/update/delete registered agents", or "register an MCP server". Covers ADK vs A2A registration modes, programmatic and interactive usage, flag reference, auto-detection from deployment metadata, Agent Registry fleet management, and troubleshooting. Part of the agents-cli skills suite. Do NOT use for deployment (use google-agents-cli-deploy).
google-agents-cli-eval
google/agents-cli
This skill should be used when the user wants to "run an evaluation", "evaluate my agent", "evaluate my ADK agent", "write an eval dataset", "analyze eval failures", "compare eval results", "optimize agent", or needs guidance on the Gemini platform eval methodology and the Quality Flywheel. Covers eval metrics, dataset schema, LLM-as-judge scoring, and common failure causes. Applies to any agents-cli project, whatever framework the agent is written in. Do NOT use for agent API code patterns (ADK: use google-agents-cli-adk-code), deployment (use google-agents-cli-deploy), or project scaffolding (use google-agents-cli-scaffold).
skill-creator
anthropics/skills
Create 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 existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
codex-pet
prime-skills/runcomfy-agent-skills
Codex Pet generator on RunComfy. Build a Codex-compatible Codex Pet spritesheet.webp + pet.json from a single reference image, drop it into ${CODEXHOME:-$HOME/.codex}/pets/ / and Codex picks it up as a custom Codex Pet next to the 8 built-ins. This skill produces the exact Codex Pet atlas Codex expects (1536x1872 PNG/WebP, 8 cols x 9 rows, 192x208 cells, 9 animation states — idle, running-right, running-left, waving, jumping, failed, waiting, running, review). Calls OpenAI GPT Image 2 edit ONCE via the local RunComfy CLI as runcomfy run openai/gpt-image-2/edit to produce a canonical Codex Pet pose, then assembles all 9 animation rows programmatically with ImageMagick micro-transforms — no Codex Pro, no $imagegen, no OPENAIAPIKEY required, only RUNCOMFYTOKEN. Triggers on "codex pet", "create codex pet", "make codex pet", "hatch codex pet", "/hatch image", "desktop pet codex", "codex pets", "spritesheet.webp", or any explicit ask to build a custom pet for OpenAI Codex.
full-output-enforcement
leonxlnx/taste-skill
Overrides default LLM truncation behavior. Enforces complete code generation, bans placeholder patterns, and handles token-limit splits cleanly. Apply to any task requiring exhaustive, unabridged output.
executing-plans
obra/superpowers
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available