Design Question - building better state machines

Hey everyone. It’s that time again. I’m looking at making a new PlayerController script.

I generally handle this via a simple set of player states inside a switch (idle, walking, nis, etc) but I can sometimes (often) create bugs as I forget to properly manage transitions between states, or forget to manage a given state’s ability to handle random player input.

I could, of course, go into abstraction and create some kind of “State” abstract class with every possible event that could transpire be handled in a must-be-overridden function, and then create a collection of these State objects and throw them in a switch… although I’m not convinced that adding the extra bloat would help or hinder me.

Do you guys have any perspective and opinion on this? How do you tend to solve these problems?

I would try GOAP in your case.
It’s a bit of a hassle to setup at first, but once it’s done, you can use it for everything else, without a need to link anything.
GOAP

That’s great! I haven’t heard of this, I’ll read it in detail. Thanks gegebel!