How to solve the problem that the attack box is not destroyed when the character's attack animation is interrupted by being hit?

Godot Version

Godot Engine v4.5.1.stable.steam.f62fdbde1 - https://godotengine.org
Vulkan 1.4.312 - Forward+ - Using Device #0: NVIDIA - NVIDIA GeForce RTX 4090

Question


My approach is to use Area2D to create the attack hitbox, and then dynamically activate and deactivate the attack hitbox in the animation track.

Of course, I also have a RESET track


also enabled deterministic

The state machine is as follows:

In any state, being hit will interrupt the current state and switch to the knockback state.

All states play animations through AnimationPlayer.

Then I noticed that if the character is hit while the attack animation is playing and the attack hitbox hasn’t closed yet, the attack state is interrupted and switches to the hit state. At this point, AnimationPlayer.play(“hurt”) interrupts the currently playing “ab/attack1”. It seems that RESET is not triggered in this case. However, RESET is triggered after AnimationPlayer finishes playing the entire animation completely.

Disable it manually when entering knockback state.