Inspiaaa / UnityHFSM

A simple yet powerful class-based hierarchical finite state machine for Unity
MIT License
1.12k stars 124 forks source link

Trigger transition from state to same state possible? #19

Closed erdostamasa closed 1 year ago

erdostamasa commented 2 years ago

I have a TriggerTransitionFromAny and I've noticed that if I'm already in the target state, it's not working. I have code in the target state's OnEnter that I have to run each time the Transition fires.

Is it possible to have a trigger transition from the same state to itself?

Inspiaaa commented 1 year ago

Hi @erdostamasa,

The fact that the "trigger transition from any" is not firing when the fsm is already in the target state is intentional. Your idea to use a second trigger transition that leads from your target state to itself again should work and will result in the OnEnter method of the target state being called each time the trigger is activated :+1:.

Here's an example of what it could look like:

fsm.AddTriggerTransitionFromAny("OnMyTrigger", "A");
fsm.AddTriggerTransition("OnMyTrigger", "A", "A");