Agent skill

Godot State Machine Advanced

by thedivergentai in thedivergentai/GD-Agentic-Skills

Expert blueprint for hierarchical finite state machines (HSM) and pushdown automata for complex AI/character behaviors.

LGPL-3.0Auto-check passedGame Development

Install Godot State Machine Advanced

skills CLI
$ npx skills add thedivergentai/GD-Agentic-Skills --skill godot-state-machine-advanced -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install thedivergentai/GD-Agentic-Skills godot-state-machine-advanced --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/thedivergentai/GD-Agentic-Skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/godot-state-machine-advanced .claude/skills/godot-state-machine-advanced && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
godot-state-machine-advanced
GitHub stars
821
Token cost
~3.3k tokens
SKILL.md length
912 words
Files
15 (incl. scripts, references)
Skills in repo
98
Repo updated
First seen
Licence
LGPL-3.0

At a glance

Expert blueprint for hierarchical finite state machines (HSM) and pushdown automata for complex AI/character behaviors.

  • Works in 3 steps: HSM Visualizer (Debug Tool) → State-Based Audio (Decoupled) → Transition Cost (Utility AI)
  • Basic FSMs are insufficient OR implementing layered AI
  • SKILL.md covers Available Scripts, Decision Tree — Which Machine?, NEVER Do (Expert State Rules) and Implementation — Scripts Are…, plus 3 more sections
  • Tasks that involve Game development

What it does

Godot State Machine Advanced is an agent skill from thedivergentai/GD-Agentic-Skills. 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.

Its SKILL.md is about 3.3k tokens, which your agent loads only when the skill is triggered. The skill folder holds 16 other files, including scripts and reference files (for example `references/hsm-implementation-cookbook.md` and `references/migration-notes.md`).

It sits in Game Development, covering Game development. It works with Godot. The repository describes itself as: The official "Long-Term Memory" for Godot 4.7+ AI Agents. A high-density library of 99 expert skills and 27 genre blueprints, providing audited, strictly typed GDScript patterns… The licence is LGPL-3.0.

When your agent uses it

  • Basic FSMs are insufficient OR implementing layered AI
  • Tasks that involve Game development

Example prompts

  • “/godot-state-machine-advanced”

Workflow steps

3 steps, taken from the step headings in SKILL.md.

  1. HSM Visualizer (Debug Tool)
  2. State-Based Audio (Decoupled)
  3. Transition Cost (Utility AI)

What it can do on your machine

Read from SKILL.md and the folder at commit 4c4d0ff. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 12 files in scripts/, which the agent can run.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • docs.godotengine.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Godot State Machine Advanced loads about 3.3k tokens when it runs, and up to ~4.4k if it reads all its reference files. Until then it costs about 97 tokens; SKILL.md has 912 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~97
When it runs · the whole SKILL.md, loaded when a task matches
~3.3k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~4.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from thedivergentai/GD-Agentic-Skills at commit 4c4d0ff, republished under its LGPL-3.0 licence (© thedivergentai). 912 words, ~3,291 tokens.

Download SKILL.mdSave it as .claude/skills/godot-state-machine-advanced/SKILL.md (or your agent's skills folder). This skill also uses 14 other files; get the full folder from GitHub.
name
godot-state-machine-advanced
description
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.

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?

NeedChooseMANDATORY scripts
Few exclusive states, no nestingFlat FSMhsm_logic_state.gd + thin parent
Nested sub-states (Move/Air/Attack children)HSMhsm_hierarchical_base.gd
Interrupt overlays (stun/menu/dialogue) then resumePushdownhsm_pushdown_stack.gd + hsm_reentry_aware_state.gd
Parallel concerns (locomotion + weapon)Concurrenthsm_concurrent_logic.gd
Pick best action by score each tickUtility cost pollingExpert 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_process orphans 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 inside enter() cause recursion crashes. Use call_deferred if immediate sub-transitioning is required.
  • NEVER hardcode state names as strings — Typos like transition_to("Idel") are silent killers. Use class_name based checks OR Constants.
Architecture & Context
  • NEVER use global singletons for state data — Coupling states to GameManager.player_health makes them non-reusable. Pass a Context object.
  • NEVER push states indefinitely — In a Pushdown Automaton, every push_state MUST 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:

Pushdown contract (from script — single exit, resume msg):

gdscript
# 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].

gdscript
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].

gdscript
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].

gdscript
# 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.

TopicReference
State contract + routinghsm-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.

Show full SKILL.md (377 more words)Show less
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_name over deep inheritance trees for layered AI behaviors.
  • Idle and Physics Processing — Why HSMs must forward _physics_process / _process into the active child (or hierarchy) every tick.
  • Using SceneTree — call_deferred transitions avoid re-entrant transition_to() crashes inside enter().
  • Godot notifications — Safe wiring timing for initial enter() relative to _ready and 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_input on the active state.
  • Timer — Finite-duration states (stun, dash) via one-shot timers that emit transition signals.
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.

© thedivergentai, LGPL-3.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 14 other files (scripts, references) in skills/godot-state-machine-advanced of thedivergentai/GD-Agentic-Skills.

  • SKILL.md
  • references/hsm-implementation-cookbook.md
  • references/migration-notes.md
  • scripts/hsm_animation_syncer.gd
  • scripts/hsm_concurrent_logic.gd
  • scripts/hsm_hierarchical_base.gd
  • scripts/hsm_logic_state.gd
  • scripts/hsm_pushdown_stack.gd
  • scripts/hsm_reentry_aware_state.gd
  • scripts/hsm_resource_state_loader.gd
  • scripts/hsm_state_context.gd
  • scripts/hsm_state_history_logger.gd
  • scripts/hsm_state_timer_component.gd
  • scripts/hsm_transition_guard.gd
  • scripts/pushdown_automaton.gd

Open the folder on GitHubat commit 4c4d0ff

Compare with similar skills

Godot State Machine Advanced next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Godot State Machine Advanced compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Godot State Machine Advanced this skillthedivergentai/GD-Agentic-Skills821—~3.3kAutomated safety check: PassLGPL-3.0
Godot Gdscript Patterns925236118/AlphaAgent10310 repos~5kAutomated safety check: PassMIT
2D Map and Scene Generator0x0funky/agent-sprite-forge4.4k—~2.9kAutomated safety check: PassMIT
Godot UI Integrationzimo-xiao-zheng/godot-ui-integration285—~1.5kAutomated safety check: PassMIT
Godot Wechat Minigame Adaptergodothub/godot-minigame187—~1.5kAutomated safety check: PassMIT
AI Game Art Pipelineybuild-ai/ai-game-art-pipeline-skill297—~1.1kAutomated safety check: PassMIT

Similar skills

  • Godot Gdscript Patterns

    925236118/AlphaAgent

    Master Godot 4 GDScript patterns including signals, scenes, state machines, and optimization.

    103 GitHub starsUsed in 10 repos~5k tokens
    Game DevelopmentAuto-check passed
  • 2D Map and Scene Generator

    0x0funky/agent-sprite-forge

    Plans and builds 2D game maps and scenes, from tilemaps and parallax backgrounds to HD-2D plates, with collision checks, a playable HTML preview and Tiled, Godot or LDtk export.

    4.4k GitHub stars~2.9k tokensUpdated 4 days ago
    Game DevelopmentAuto-check passed
  • Godot UI Integration

    zimo-xiao-zheng/godot-ui-integration

    Build or revise Godot UI from an approved design, separated art, or a visual reference when scene structure, gameplay binding, and runtime visual verification all matter.

    285 GitHub stars~1.5k tokensUpdated 1 mo ago
    Game DevelopmentAuto-check passed
  • Godot Wechat Minigame Adapter

    godothub/godot-minigame

    Apply the bundled self-contained Godot WeChat Mini Game adapter kit to an official Godot checkout.

    187 GitHub stars~1.5k tokensUpdated 25 days ago
    Game DevelopmentAuto-check passed
  • AI Game Art Pipeline

    ybuild-ai/ai-game-art-pipeline-skill

    Provider-neutral open-source skill for planning and producing game-runtime art assets and animation: static props/icons, canonical character sheets, combat sprites, 3D/video motion references…

    297 GitHub stars~1.1k tokensUpdated 3 mo ago
    Game DevelopmentAuto-check passed
  • MCP Driver

    RandallLiuXin/GodotMaker

    Runtime debugging and live project inspection via godot-mcp.

    550 GitHub starsUsed in 1 repo~1.1k tokens
    Game DevelopmentAuto-check passed

More from thedivergentai/GD-Agentic-Skills

All 98 skills in this repo
  • Godot 2D Animation

    thedivergentai/GD-Agentic-Skills

    Expert patterns for 2D animation in Godot using AnimatedSprite2D and skeletal cutout rigs.

    821 GitHub stars~3.6k tokensUpdated 1 mo ago
    Auto-check passed
  • Godot 3D World Building

    thedivergentai/GD-Agentic-Skills

    Expert patterns for 3D level design using GridMap with MeshLibrary, CSG constructive solid geometry, occlusion, and runtime GridMap builders.

    821 GitHub stars~3.3k tokensUpdated 1 mo ago
    Auto-check passed
  • Godot Adapt 2D To 3D

    thedivergentai/GD-Agentic-Skills

    Expert patterns for migrating 2D games to 3D including node type conversions, camera systems (third-person, first-person, orbit), physics layer migration, sprite-to-model art pipeline, and control…

    821 GitHub stars~4.7k tokensUpdated 1 mo ago
    Auto-check passed
  • Godot Adapt 3D To 2D

    thedivergentai/GD-Agentic-Skills

    Expert patterns for simplifying 3D games to 2D including dimension reduction strategies, 2.5D fake-depth, isometric ports, camera flattening, physics conversion, 3D-to-sprite art pipeline, and…

    821 GitHub stars~4.5k tokensUpdated 1 mo ago
    Auto-check passed
  • Godot Agent Vision

    thedivergentai/GD-Agentic-Skills

    Agentic eyes for Godot work: cross-platform screenshot CLI (asset/region/window/screen) to budgeted WebP, TEMP editor viewport bridge under .gdskills/, and Taste Receptor Atlas v2 (~237…

    821 GitHub stars~3.5k tokensUpdated 1 mo ago
    Auto-check passed
  • Godot Animation Tree Mastery

    thedivergentai/GD-Agentic-Skills

    Expert patterns for AnimationTree including StateMachine transitions, BlendSpace2D for directional movement, BlendTree for layered animations, root motion, transition conditions, advance…

    821 GitHub stars~3.6k tokensUpdated 1 mo ago
    Auto-check passed

Works with

Questions about Godot State Machine Advanced

What does Godot State Machine Advanced do?

Expert blueprint for hierarchical finite state machines (HSM) and pushdown automata for complex AI/character behaviors. Godot State Machine Advanced is an agent skill from thedivergentai/GD-Agentic-Skills. Expert blueprint for hierarchical finite state machines (HSM) and pushdown automata for complex AI/character behaviors.

When should I use Godot State Machine Advanced?

Godot State Machine Advanced fits situations like: basic FSMs are insufficient OR implementing layered AI; tasks that involve Game development.

How do I install Godot State Machine Advanced in Claude Code?

Run `npx skills add thedivergentai/GD-Agentic-Skills --skill godot-state-machine-advanced -a claude-code`. Or copy the skill folder (skills/godot-state-machine-advanced in thedivergentai/GD-Agentic-Skills) into .claude/skills/godot-state-machine-advanced in your project. Claude Code loads it when a task matches its description.

How do I install Godot State Machine Advanced in Codex?

Run `npx skills add thedivergentai/GD-Agentic-Skills --skill godot-state-machine-advanced -a codex`. Or copy the skill folder (skills/godot-state-machine-advanced in thedivergentai/GD-Agentic-Skills) into .agents/skills/godot-state-machine-advanced in your project. Codex loads it when a task matches its description.

Can I use Godot State Machine Advanced in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add thedivergentai/GD-Agentic-Skills --skill godot-state-machine-advanced -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/godot-state-machine-advanced, .gemini/skills/godot-state-machine-advanced, .github/skills/godot-state-machine-advanced and .opencode/skills/godot-state-machine-advanced in your project.

What does Godot State Machine Advanced need to run?

SKILL.md names no scripts, command-line tools or credentials: Godot State Machine Advanced is instructions for the agent only.

Does Godot State Machine Advanced access the network?

SKILL.md names 1 domain. As links in the text: docs.godotengine.org. This is read from the text; nothing was executed.

Is Godot State Machine Advanced safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Godot State Machine Advanced use?

Godot State Machine Advanced is published under the LGPL-3.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Godot State Machine Advanced use?

About 3.3k tokens (SKILL.md is roughly 13k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 1.1k tokens, read only when the agent opens those files.

What are the alternatives to Godot State Machine Advanced?

Skills that share tags, products or a category with Godot State Machine Advanced: Godot Gdscript Patterns (925236118/AlphaAgent, 103 stars), 2D Map and Scene Generator (0x0funky/agent-sprite-forge, 4.4k stars), Godot UI Integration (zimo-xiao-zheng/godot-ui-integration, 285 stars) and Godot Wechat Minigame Adapter (godothub/godot-minigame, 187 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Godot State Machine Advanced?

thedivergentai (a GitHub user) maintains it in thedivergentai/GD-Agentic-Skills, which has 821 GitHub stars. The repository holds 98 skills in this directory. The repository was last updated on September 9, 2026.

Source: thedivergentai/GD-Agentic-Skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.