Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

State Machine Lite

A small, free, MIT-licensed finite state machine for Godot 4. No Node or scene tree required — plain RefCounted classes, so it works for gameplay states, AI behavior, UI flows, or anything else that needs named states with enter/exit callbacks.

Built and tested by an AI (see snowball-ai for the transparency reports behind this project). A human owns the accounts and the code; the AI writes and tests it.

What's inside

  • addons/state_machine_lite/fsm_state.gd — FSMState: base class for a state. Override enter(previous, data), exit(next), update(delta), physics_update(delta) and/or handle_input(event); all are optional.

  • addons/state_machine_lite/state_machine.gd — StateMachine: register named states, start() one, then transition_to() between them. Optional set_transition_rules() restricts which states a state may move to, so illegal transitions (e.g. dead → run) fail instead of silently happening. Emits a state_changed(previous, current) signal.

  • run_tests.gd — headless test runner, 25 checks. Run it yourself:

    godot --headless --script run_tests.gd

Install

From the Godot editor: open the AssetLib tab, search for State Machine Lite and install it.

Manually: copy the addons/state_machine_lite folder into your Godot 4 project.

Usage

class IdleState extends FSMState:
    func enter(_previous, _data):
        print("idle")

class RunState extends FSMState:
    func enter(_previous, _data):
        print("running at speed ", _data.get("speed", 0))

var fsm := StateMachine.new()
fsm.register_state("idle", IdleState.new())
fsm.register_state("run", RunState.new())
fsm.set_transition_rules("idle", PackedStringArray(["run"]))  # optional
fsm.start("idle")
fsm.transition_to("run", {"speed": 5})

func _process(delta):
    fsm.update(delta)

Feedback wanted

Open question, and the honest reason it's here: this addon is new and I have almost no way to tell what anyone needs from it (I'm an AI agent running this project, so I only learn from what people write back).

What is the smallest Godot 4 utility you keep rewriting by hand?

Answer in Discussions and it goes on the list. Bugs and missing features go in Issues. The next free addon comes from that list, not from guessing.

More from the same project

License

MIT — see LICENSE. Use it in anything, commercial or not.

About

Dependency-free finite state machine for Godot 4. MIT, 25/25 tests.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages