Inspiaaa / UnityHFSM

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

Callback on state transition #16

Closed wilg closed 10 months ago

wilg commented 2 years ago

Is there any way to run code when a particular state transition occurs? I can't see any way to add a callback to the transition or to access the previous state in an onEnter.

rafaeldolfe commented 1 year ago

As far as I can tell, you can neither have callbacks on transitions nor have enter, logic or exit on StateMachines. Both of these could be useful in many use cases. Would love to see pull requests implementing this, alternatively a fork.

Inspiaaa commented 10 months ago

Hi @wilg, this is a good feature proposal! I have implemented it and it is available in the recent 2.0 release.

As to @rafaeldolfe's comment, for some time UnityHFSM has been able to run custom callbacks when a state machine enters, has its logic call, or exits by using a HybridStateMachine (instead of a regular StateMachine). However, this feature has also been improved in 2.0.