Download

Buffering input for FSM

I’m working on a very simple combat system, there aren’t any many-to-one “chains” of inputs like in fighting games, but I want to let you buffer your commands, such that pressing something like “A,A,B” and then taking your hands off the controller would result in your guy launching all three attacks. It seems like the best place to encapsulate the logic of which button inputs transition into which attacks would be the animation tree, as it would be very simple to set up something like this, where each rectangle is an animation and each circle is an input that satisfies the transition rule:

Combo FSM.png

The problem I’m having is figuring out how I can phrase my transition rules. In plain language, assuming my input buffer is some TArray<EInputEnum> on the character or the controller, the rule I’m trying to enforce is “At the end of every attack animation, check the input buffer. If it’s not empty, check for a transition rule requiring buffer[0], then run buffer[0].Remove”. I don’t have an execution pin in the graph for transition rules, which means I can’t cast and check the buffer directly, and making a boolean for every possible transition rule would quickly turn into a mess of spaghetti code that I’d be wasting tons of cycles checking every animation update.

Is there a cleaner, friendlier design pattern to tackle what I’m describing? It feels like I’m missing something obvious that would simplify things.