Problem description
So I have a pretty simple FSM with 4 states: Idle, Walk, FollowUntil (follow enemy until it's not in attack range), Attack.
I want to have an opportunity to make transitions almost from every state to every other state. And sometimes I want to configure some transition using scripts. But it turns out I have to make 4 (states amount) * 3 (other states amount) = 12 transitions. Looks pretty bad... And I have to make even more when I make new states. And it turns out we have geometry progression of transitions...

Yes, I know we can call switch_state() on FSM to switch states. But it makes transitions uncustomizable. And mixing switch_state() and events are kinda bad decision
Possible solutions
Remove transitions
First thing that comes to mind is to remove transitions at all and make function like _handle_transition(to_state: String) in FSMState template. So you can process needed transitions using code
Smart solution - notify transitions during switch_state()
Ok. So the problem is "I want to change states from one to another and also have opportunity to customize some transitions". To solve this we can make switch_state() the desired way to change states instead of fire_event(). And in switch_state() function we will seek for child transition that satisfies our logic and call _on_transition() of this node if found
Problem description
So I have a pretty simple FSM with 4 states: Idle, Walk, FollowUntil (follow enemy until it's not in attack range), Attack.
I want to have an opportunity to make transitions almost from every state to every other state. And sometimes I want to configure some transition using scripts. But it turns out I have to make 4 (states amount) * 3 (other states amount) = 12 transitions. Looks pretty bad... And I have to make even more when I make new states. And it turns out we have geometry progression of transitions...
Yes, I know we can call
switch_state()on FSM to switch states. But it makes transitions uncustomizable. And mixingswitch_state()and events are kinda bad decisionPossible solutions
Remove transitions
First thing that comes to mind is to remove transitions at all and make function like
_handle_transition(to_state: String)in FSMState template. So you can process needed transitions using codeSmart solution - notify transitions during
switch_state()Ok. So the problem is "I want to change states from one to another and also have opportunity to customize some transitions". To solve this we can make
switch_state()the desired way to change states instead offire_event(). And inswitch_state()function we will seek for child transition that satisfies our logic and call_on_transition()of this node if found