Meteorite logoMeteorite
Back to videos

Godot State Machines: Enum or a Node Per State?

Most Godot Projects Don't Need a Node Per State Godot state machines: the enum version, the node-per-state version, and how to tell which one your project actually needs. Four booleans give you sixteen possible states, and you probably wrote logic for six of them. Press dash and attack in the same frame and one of them disappears — no error, no warning, it just never runs, because the first branch returns before the second one is reached. The fix is one variable that holds what you are, and exactly one function allowed to change it. That carries you to about five states. Then it stops: every state starts wanting its own timer, its own animation, its own cleanup, and all of it lands in the same match block. Two hundred lines later the coupling isn't gone — it just moved into one function. A node per state solves that, and costs you six files instead of one. Whether that trade is worth paying comes down to three questions, and for most projects the answer is still the enum. Recorded in Godot 4.7. Chapters 0:00 Four booleans, sixteen combinations 0:21 What's in this video 0:31 What a state machine actually is 0:54 One variable, one function 1:30 Where the enum stops 1:59 One node per state 2:37 Which one you need 3:13 What a node per state costs Godot logo © Godot Foundation, licensed under CC BY 4.0 — https://creativecommons.org/licenses/by/4.0/ — https://godotengine.org/press/ Godot Engine is free and open source software released under the MIT license. #godot #tutorial #gameengine #gamedev

Suggested videos