# How do I restart an animation that is already playing using SetTrigger?

I have set up a relatively simple example scene with one enemy.

This enemy is controlled with an animation controller. In this animation controller, I have set up a trigger named "Hit".

The enemy plays an idle animation, and when my hero character shoots him, I set the trigger "Hit" via script like this:

_animator.SetTrigger("Hit");


This causes the animation controller to react to it, and it transitions from "Idle Animation" to "Hit Animation":

The hit animation is 3 seconds long. After it has completed, the animation controller will automatically transition back to the "Idle Animation".

I would like make it so that the hero character can shoot the enemy even though he is already playing the hit animation. Let's imagine you use a machine gun to shoot him repeatedly quickly.

However, when I call

_animator.SetTrigger("Hit");


while the hit animation is already being played, nothing happens.

As I currently understand it, this makes perfect sense as the Trigger triggers the transition from animation A to animation B, and if we're already at animation B, then there can be no transition.

The transition will only kick in if the animation controller is currently playing the "Idle Animation" as it can then transition to the "Hit animation"

What could I do to "restart" the hit animation?

Thank you.

• Presumably you've tried using transitions from the "Any State" with "Can Transition To Self" enabled? You may want to then treat your various hit variables as separate triggers rather than integer values. Jun 5 '20 at 13:56