Death state animation playing every frame (2D Platformer)

Godot Version

Godot 4.3

Question

Hello, I was using a state machine for my 2D platformer character, but when getting hit and playing the death state, it seems to repeat it every frame instead of once. Changed from _physics_process to _process, but it keeps happening. Has something like this happened to you before, and how did you solve it? Would it be better to keep it as a function in the main player script instead of a state in the state machine?

using await within a repeating function like _process every frame will still repeat, it doesn’t halt further calls to _process every frame. So you may have 1.5 * 60 more calls than you expected.

It seems like you should run this code only when the state transitions to death, not checking every frame.

1 Like