derkork / godot-statecharts

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

AntHill demo calling "initialized" too early #31

Closed BencePaul closed 1 year ago

BencePaul commented 1 year ago

Hi,

Thanks for the great addon to Godot. I am a newbie to Godot so please excuse any mistakes below. I was trying to understand the AddOn better by running the AntHill demo in Godot v4.1.1(stable) and the ants never switched from "Initializing" to "Seeking food" state. I used the debugger (nice tool) to see that the signal was never acted on. So I added a timer to the Ant scene, with a wait time of 3 seconds. When it timed out, I sent the signal again (via timer.timeout.connect(func (): state_chart.send_event("initialized")), and it successfully started the demo.

I'm sure there's a more elegant way of doing this, but it seems that the signal is sent too early?

derkork commented 1 year ago

Yes this is a side effect of the fix for https://github.com/derkork/godot-statecharts/issues/28 . The initial state of the state chart is only entered with one frame delay, so that nodes higher up in the tree have a chance to run their _ready functions before the state chart calls any state logic. Sadly this broke the ant demo because it runs a state transition in _ready. It is easily fixed though by running the state transition one frame delayed as well, e.g. like this:

image

I'll push a fix for this and add some info in the manual about it.