I’ve got an AI system which uses behavior trees and blackboards for zombies. The zombie can have various ‘states’ which determines which branch of the behavior tree we’re visiting.
None - NULL condition, do absolutely nothing
Spawning - play a spawning animation
Active - Main branch of the behavior tree
Dying - Play the death animation
Dead - slowly sink into the ground
Frozen - Freeze in place
Taking Damage - Play a received hit animation
So, here’s the issue… you can freeze a zombie and it freezes in place until it thaws out over time. You can freeze a zombie at any time, including when it spawns, when its active, etc. The way I have implemented this is by saving the zombies ‘prior state’ before it gets frozen. When the zombie unfreezes, I revert its active state to the prior state. So, if a zombie gets frozen in the middle of spawning, it will resume spawning from where it left off if it thaws out.
The wrinkle is with the “Taking Damage” state while the zombie is frozen and active at the same time. The ideal situation is to create a “stack” data structure which stores a list of creature states. So, if the zombie gets frozen while its spawning, I’d just push the ‘frozen’ state onto its state stack. When the freezing effect wears off, I’d pop it off the stack and it would resume spawning. If the zombie is active, frozen, and then takes damage, I’d push the ‘take damage’ state onto the stack of [Active, Frozen] such that it becomes [Active, Frozen, Taking Damage]. When I go to process that stack event, I… play the taking damage animation when I’m frozen? I’m not quite sure.
Has anyone else attempted to use stacks as a way to manage an AI state machine? Is there anything within the AI blueprints to support stack data structures, or do we have to create our own?