Problem with Finite State Machine

Condition order is important, I wonder if that can have impact. While I doubt it’ll fix this for you, I’d always strongly recommend the “is finished” be underneath any animation events, not above.

As an interesting aside, I wonder if anything changes if you make a hard requirement for it to be in the current state as part of that transition (e.g. add "The variable enemyFSM of gMelee is “Attack” as a condition in that event).

Sorry, I did not get it. Since I’m already saying that gMelee is attacking with a variable.

Or did you mean something like that?

No, I mean more adding a condition that ensures you’re in the state you expect to be in presently to the transition.

So let’s say you’re in the “Attack” FSM sheet. While the main FSM sheet will already require “enemyFSM of gMelee = Attack”, still add that same condition into your transitions.

Oh I see, check if the enemy really is in that state.

It might work. However, I have a strange look at using “Trigger once” in FSM. I was messing around here now and realized that if I add the same before going into any state, some enemies don’t work, they just stay put except the same enemies (those that moved first). Using “For Each” can I use Trigger once?

EDIT: Ok, I won’t be able to in the game anymore for now, then I’ll come back to show the changes and I’ll also make a debugger for each enemy and check if all are correctly entering their state and exiting them…

Unfortunately, Trigger Once only impacts the first instance of an object in a For Each event.

I’m hopeful at some point this enhancement request gets picked up: TriggerOnce should apply individually to each instance when used in a ForEach loop · Issue #2591 · 4ian/GDevelop · GitHub

Just like I was thinking and it’s like the bug you reported. I removed everything I had as a “trigger once” where I was doing some enemy behavior change, and none of them froze.

I will do more testing and try to debug everything I can to fix this problem. But the fact is, it didn’t happen again. But I’m still not sure it won’t happen again. So I’ll be updating here in case there’s anything.