derkork / godot-statecharts

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

Transitioning to the root states throw exception #3

Closed Remi123 closed 1 year ago

Remi123 commented 1 year ago

When a transition is set to the root compound state ( the child of the StateChart node ), the path resolution throw at compound_state.gd at lign 188 : _handle_transition(...)::get_parent()._handle_transition(transition, source) :

image

It seems like returning to this statenode tries to get the handle_transition of the state chart.

My reasoning was that I was trying to, for a lack of better word, return to the normal state, which is falling. I tried to transition to the root compound state since I have my logic that work during initialization. It's confusing since the root compound state has a field named initial state so I though it would work.

The workaround for now is that my transition return to the falling state instead of the root node.

Possible solution : Add an handle_transition function in state_chart that let the one and only one child resolve it, as if it was called by _ready

derkork commented 1 year ago

I'm not quite sure how your setup looks. Could you maybe post your node tree and indicate from which state you are transitioning to the root state? The "initial state" of the root should work, and you should definitely not see such an error message so I suspect an oversight on my part. Knowing your setup would make it easier for me to reproduce it.

derkork commented 1 year ago

Ok I could reproduce it with this setup: image

This would also occur if any child would refer back to its parent. I handle this case now and now this works as expected:

https://user-images.githubusercontent.com/327257/231439444-446f8641-f82d-4ca1-bec2-2d1f4ec48edb.mp4

Root -> A (because A is initial state) -> B (timed transition) -> Root -> A ... etc.

derkork commented 1 year ago

Fixed in 0.1.1. I submitted this to the asset library, should be available once the submission is approved. Thanks for reporting this, it really helps having other people than me using it and finding things I overlooked 👍