Inspiaaa / UnityHFSM

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

feature request: OnActiveStateChanged event? #22

Closed santutu closed 6 months ago

santutu commented 1 year ago

I suggest to add an Active StateChanged event to StateMachine class to track the state. I took a quick look at the code, and I think it would be possible by invoking the event at StateMachine's ChangeState method. if this function is ok, I am willing to do pull request.

simple example fsm.OnActiveStateChanged += (activeState)=> Debug.Log(activeState);

Monsoonexe commented 1 year ago

This event sounds pretty useful.

On Sun, May 14, 2023, 7:11 AM santutu @.***> wrote:

I suggest to add an Active StateChanged event to StateMachine class to track the state. I took a quick look at the code, and I think it would be possible by invoking the event at StateMachine's ChangeState method. if this function is ok, I am willing to do pull request.

simple example fsm.OnActiveStateChanged += (activeState)=> Debug.Log(activeState);

— Reply to this email directly, view it on GitHub https://github.com/Inspiaaa/UnityHFSM/issues/22, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKNKVBNQHX53I5EOOQE3JZTXGDRXHANCNFSM6AAAAAAYBF6IAQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Inspiaaa commented 6 months ago

Hi @santutu, Thanks for the feature request and the implementation of it in your pull request! I especially appreciate that you added unit tests. Thanks a lot!

I have merged your PR and made a few small changes. It will be released with the upcoming 2.1 version.

As I have not encountered a real-world use case for this feature myself, I'll be rolling out this feature conservatively, starting with a minimal version and seeing how well it fares. Future versions may then include enhancements, once I know more about how this feature is used.

woodward54 commented 6 months ago

+1, this feature would also be useful for my project

Inspiaaa commented 6 months ago

The "state changed" event is now available in the latest release (2.1) :+1:

woodward54 commented 5 months ago

Thank you! @Inspiaaa