Restarting animation state node with xfade

Godot Version

4.2

Question

Is it possible to restart an animation state machine node with a xfade?

I have an enemy with an animation state node for “hurt” which plays a hit animation when the actor takes damage. I would like to restart the animation if the actor gets hit again while still playing the hit animation. I can ask the node to restart using AnimationMixer.start() but then the animation jumps back to frame zero with no xfade.

Is there a way I can have my character restart the hit animation smoothly, essentially crossfading into itself? Or am I maybe thinking about this wrongly?

I don’t think that’s possible. Even enabling AnimationNodeStateMachine.allow_transition_to_self will restart the animation without xfade. You could workaround it by having a second node in your state machine with the same animation and traveling between them with xfade like:

	if playback.get_current_node() == 'hit':
		playback.travel('hit_2')
	else:
		playback.travel('hit')
``