derkork / godot-statecharts

A state charts extension for Godot 4
MIT License
679 stars 33 forks source link

compound state with an initial state and an automatic transition to another child state will activate both states #100

Closed HymnStudio closed 3 months ago

HymnStudio commented 3 months ago

Here I use the example scene in performance_test, add a transition node to Root compound state, which is an automatic transition to StateB with no delay time and guard. image

By doing so, a compound state can have its two child both active at the same time: image

I am not sure if it is intended, but here is my understanding: when entering compound state,1. it first calls the base state _state_enter() method, triggering the automatic transiton to active StateB,2. then it calls its _state_enter() method, activating StateA according to its initial state setting: image

derkork commented 3 months ago

Thanks a lot for reporting this! This definitely looks wrong. A compound state should under no circumstances have more than one child state active at any given time. So i think the correct flow should be

So an immediate transition will supersede any initial state (which is the idea behind this expect_transition flag, but it obviously is not properly set here). I will do a bit of investigation as such setups may lead to very interesting edge cases and I'll probably also need to update the manual to describe the behaviour that can be expected.

derkork commented 3 months ago

I found another edge case if the transition leaves for a totally different state. Then the initial state is entered but never exited. Fixed this as well.