Inspiaaa / UnityHFSM

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

Feature request: add OnTransition callback to Transition class #24

Closed rafaeldolfe closed 1 year ago

rafaeldolfe commented 1 year ago

Add OnTransition event to the Transition class, so that when you add a transition, and that transition happens, a specific function can be called.

Otherwise you have to do things like setting the function in OnEnter/OnExit and then check for the state or store separately which transition is being used. Not very easy to use.

Monsoonexe commented 1 year ago

I like this idea. You can run logic on specific state transitions.

On Wed, May 17, 2023, 5:34 AM Rafael Dolfe @.***> wrote:

Add OnTransition event to the Transition class, so that when you add a transition, and that transition happens, a specific function can be called only for that transition. Otherwise you have to do things like setting the function in OnEnter/OnExit and then check for the state or store separately which transition is being used. Not very readable.

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

rafaeldolfe commented 1 year ago

Let's hope and pray someone can implement this (or just gimme the code for it 😀). I'm too swamped with work rn to do it myself 😭

Monsoonexe commented 1 year ago

Looks all you need to do is override ShouldTransition(), and if you would return true, then raise the event.

On Wed, May 17, 2023, 5:45 AM Rafael Dolfe @.***> wrote:

Let's hope and pray someone can implement this (or just gimme the code for it 😀). I'm too swamped with work rn to do it myself 😭

— Reply to this email directly, view it on GitHub https://github.com/Inspiaaa/UnityHFSM/issues/24#issuecomment-1551327143, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKNKVBOGOTYEY4C2XXU2PHTXGTB6FANCNFSM6AAAAAAYFAXWNM . You are receiving this because you commented.Message ID: @.***>

rafaeldolfe commented 1 year ago

Makes sense. Would that work also for trigger transitions?

Inspiaaa commented 1 year ago

Hi @rafaeldolfe, Your idea for this new feature is really good! I'm going to implement this feature in the next release (1.10). I'm already working on 1.10 and you can see the changes in the release branch. If you monitor the release 1.10 branch, you'll soon see that I'm taking a different approach from @Monsoonexe's proposal. My reason for a different approach is based on the timing system so that the on transition action can also be called when a transition is delayed (pending state system). As to @rafaeldolfe's last comment, the answer is yes. It will work with all transition types.

rafaeldolfe commented 1 year ago

Sounds awesome! Will be watching 👌

tomsseisums commented 1 year ago

This is already available in yet unreleased, but available 2.0 version. :)

bvggeneral commented 1 year ago

@Inspiaaa I believe this is done with 2.0, right? 🎉 I'd be down to close this issue.

rafaeldolfe commented 1 year ago

(Comment above is me) I'll close this!