[Solved] Issue with changing enemy animation

So, I have this working with 3 other enemies, and it works fine. I have a HP variable for each enemy. when it gets to zero, I have it change to a death animation. On the last frame (frame 3), I have it delete itself. It works on everything else. However, on one enemy, instead of dieing, it switches to the first frame of the idle (animation 0), and it does NOT delete. If i remove the animation change and just delete it, it works fine. it is something about changing to that animation. I have also tried calling the animation number instead of the name.

I am making this game for a game jam, and need to stop working on enemies and start working on the map/sound, but I am stuck here

The problem comes from those events. When you switch to an animation, it starts it again from the beginning. Therefore, your animation will never reach 3 frames, since you are always restarting it and thereby setting the animation frame to 0. what you meant to do is this:

When it is dead, change the animation once, and only continuously check if the time has come for it to be deleted.

Note that this may not work correctly if multiple monkeys are being killed at once, because the trigger once triggers the event generally once, not once per object. Use the trigger once per object extension to have a failsafe event:

Still Isn’t Working. Now it isnt even pausing on the idle. it is acting as if the enemy has taken no damage. Here are the changed settings:

And here is a video showing what it is doing now, as well as how the other enemies react to being hit:
Here is a video

and here is the OTHER enemies. they are working as intended, even though they have the original setup:

Also, what are you using to trigger the ‘dead’ state? I don’t think I have seen that half heart icon before. Is it an extension?

Is using an object variable not a good idea? note: My enemies have different amounts of hp, and different elements of attacks do different damage to each creature

That was what I thought too, and it used to be like that. But it hasn’t been the case with GDevelop lately. Once it triggers an animation, the Set animation... action won’t restart it.

It’s the health extension.

But to your problem. I’m wondering it these two events are countering the MonkeyHP < 0 event :


In that they set the animation from “die” to “Idle” and the animation number will never reach 3.

1 Like

Huh, TIL. I use state machines where I only change my animation once anyways, so I hadn’t had such a scenario in a while.

(By the way I’d recommend using a Finite State Machine for your enemies, that could make your life easier)

1 Like

This was it! Thank you. I did not even see that conflict. I fixed it by adding a “MonkeyHP>0” to both of the alert statuses. So, it will only play the attack or idle if the health is over zero, else it deletes the sprite.

I have not looked into extensions much, but will do so next time. I joined the metroidvania jam, and am working as fast as possible before the 15th of march. Didn’t help that I decided to learn a new engine (I have worked with GBStudio and Solarus before, but not really anything more complex like this). I am spending more time figuring out simple things that actually adding to the game. But, that is how you learn! Anyway, thank you

I will look into Finite states during the next project! If it makes life easier, I am all for it. sadly, I am running out of time for this project, so I don’t have time to redo what I have.