← All examples

godot components

Hierarchical state machine with event bubbling and history

Define nested states in code with event transitions that bubble from the leaf to its ancestors, guards, entry and exit in hierarchy order and shallow history, so shared behavior lives in parent states.

What this component contains

  • ATTRIBUTION.md
  • LICENSE
  • README.md
  • baltor_test.gd
  • component.json
  • hierarchical_state_machine.gd
  • inspect_gdscript.py
  • run_tests.gd
  • test_package.py
  • tests/test_hierarchical_state_machine.gd
  • verification/native.json

How it works

Class
BaltorHierarchicalStateMachine, extends RefCounted
Methods
add_state(state_name: StringName, parent_name: StringName = &"", on_enter: Callable = Callable(), on_exit: Callable = Callable(), on_update: Callable = Callable()) -> bool; set_initial(parent_name: StringName, child_name: StringName) -> bool; set_history(state_name: StringName, enabled: bool) -> bool; add_transition(from_state: StringName, event: StringName, to_state: StringName, guard: Callable…
Signals
state_entered, state_exited, transitioned
Placement
res://baltor/godot_components/hierarchical_state_machine/

Recorded checks

godot 4.7.2.stable.official.ed1daf0bf

  • godot_parse_check_only
  • godot_gdscript_tests
  • godot_tests_reject_gutted_component
  • godot_editor_import
  • godot_contract_reflection
  • godot_readme_usage_compiles

Limits to consider

A subset of statecharts: no orthogonal (parallel) regions, no deep history, no internal transitions and no delayed events. Callbacks run synchronously; sending an event from inside a callback is not queued and runs immediately. Verified with Godot 4.7.2 headless; written against the Godot 4.3 API.