derkork / godot-statecharts

A state charts extension for Godot 4
MIT License
761 stars 39 forks source link

Double _on_enter() due to compound_state #1

Closed Remi123 closed 1 year ago

Remi123 commented 1 year ago

It took me a while to reproduce but I found out that some architecture can trigger on_enter and on_exit twice.

Small explanation of my nodes : I have a character that move in the Move state, then once I click it goes into Jump state and immediatly transition to a Falling state. I've connected the on_enter() function of the Move and Falling state to a function that print respectively Move and Falling enter with the timestamp.

With this setup : image Produce this result : image

However this architecture : image Airborne also print its name on enter Produce this result : image

During transition, it seems that compoundstate trigger the on_enter() and on_exit of his children if it's the target node. I've looked into the reference statechart.io website to see if it's an intended behavior, but didn't find any. I believe this is unintended behavior.

However I'm not familiar enough with the code to know why the root compoundstate isn't affected.

Thank you

derkork commented 1 year ago

Hey Remi123, thanks a lot for reporting this. It is indeed not intended behaviour. The "Airborne" state will activate it's default child state when entered. However since this is part of a transition it actually should not do this. I have added a fix for this and will release an update with it. I have also added some improvements to the state chart debugger so it can track state change events for you without you having to litter your code with print statements:

image

In the screenshot you can now also see the fixed behaviour, when AA transitions to ABA , ABA will only be activated once.

Remi123 commented 1 year ago

Thank you that was fast