Godot 4 State Machine + Save/Load Kit: Tested GDScript with Playable Demo
For Godot 4 developers who want a clean state machine and save/load without writing them from scratch. Two small, readable building blocks, a playable demo and 35 automated tests you can run yourself.
See how it works first: our free tutorial, A simple state machine and save system in Godot 4, explains the approach with code.
- State machine: StateMachine and State nodes. Each state (Idle, Move, Dash...) is its own short script with enter, exit, update, physics_update and handle_input. Includes a state_changed signal, state history and transition_back().
- Save/load: a SaveManager autoload. Put a node in the "persist" group, add save_data() and load_data(), and it saves to JSON slots. Includes slot listing for a load menu, safe writes, a version number with a migrate() hook, and Vector2/Vector3 helpers.
- Demo: move, dash, collect coins, then save and load with F5 and F9.
- 35 automated tests you can run yourself, and a README that explains every step.
Not the right fit if you use Godot 3, or you need encrypted saves (saves are plain JSON so you can open them to debug).
Questions
- How do I run the tests? From the project folder, run godot --headless --import and then godot --headless res://tests/test_runner.tscn. You should see 35 PASS lines.
- What if the game crashes mid-save? A save is written to a temporary file first and then swapped in, so the old save is kept.
- Can I use it in a commercial game? Yes, in as many of your own games as you like, with no credit needed.
Next step: Your First Finished Godot Game ($19), a 51-page workbook to scope, plan and ship a small 2D game.
Good to know
- Made and tested with Godot 4.7.2, GDScript only. Other 4.x versions have not been tested. Not for Godot 3.
- License: use it in as many of your own games as you like, free or commercial, no credit needed. Please do not resell the kit itself.
- Saves are plain JSON and are not encrypted.
- Not affiliated with or endorsed by the Godot Foundation.
Please note: this is a digital download; nothing is shipped. It is for education and personal use only and is not financial, tax, legal or medical advice. You make your own decisions. Made from scratch by Kitson Workshop.