u/Different_Stranger30

Guidance on Implementation of a Hierarchical Finite State Machine

Guidance on Implementation of a Hierarchical Finite State Machine

Hello,

I'm new to GameDev and don't have a background in software development so sorry if this is a dumb question.

I have built an FSM using this video as a guide: https://youtu.be/K9JizfQ-oFU?si=EPgMUu7r_a5EWFr0

I want to extend it into a HFSM. My plan to do so is:

  • give states a "state parentState = null" variable in the parent State class
  • Update parentState on creation of sub classes where applicable, such as the "airborne" superstate for the "jumping", "double jumping", "falling" substates, etc.
  • Update the StateMachine class functions to also call parent states if that state is not null.
  • Do some sort of shared parent check prior to calling parent classes for transition functions, like enter and exit. Thinking a hash table check for a shared parent and if it comes up with a value keep calling the enter/exit function on sub parents until reaching that value.

Does this seem like a reasonable way to turn that code into a HFSM? Am I missing any concepts or issues in my idea?

u/Different_Stranger30 — 3 days ago