State Trees in Unreal
- #unreal #gamedev #state-machines
- 190 words, Read time 0 minutes, 57 seconds
Can't wait for the upcoming holidays.
I was building something at work that needed clear, distinct stages, the kind of thing that runs like a show or a stage play: this happens, then that happens, then we move on. My first instinct was to roll a state machine from scratch, the way people would back in Unity.
Then I found out Unreal ships with State Trees built in, and it handed me most of what I was about to write by hand. Conditional transitions, branching hierarchical states, and modular design to scale up and down. All the machinery I was dreading, already there.
The mental model is refreshingly simple. You define these little things called Tasks, drop them into a State, and when that State is entered its Tasks run in the order and manner you set up. That is basically it. No hand-rolled enum soup, no giant switch statement quietly rotting inside a tick function.
It saved me a genuinely embarrassing amount of time and effort. Turns out a decent chunk of those Unreal gigabytes is busy doing the work so I do not have to.
Anyway. Holidays soon.