# Unity Animation isn't played once despite using trigger parameter

From the unity documentation: https://docs.unity3d.com/Manual/AnimationParameters.html

Trigger parameter: a boolean parameter that is reset by the controller when consumed by a transition (represented by a circle button)

So it should play the animantion once right?

In my current game I already set my animation transition condition to trigger, then in gameObject script I also set the parameter, but it plays more than once.

Here are my animation parameter

Here are my animation transition condition

And here are my gameObject script to set the parameter

Animator anim;
Start() {
anim = GetComponent<Animator>();
}

void shoot() {
anim.SetTrigger("shoot");
}


EDIT: this is the transition out of PlayerShoot, returning to PlayerIdle

• Can you show us your transition back out of PlayerShoot, returning to PlayerIdle? – DMGregory Aug 17 '18 at 17:51
• @DMGregory ok, I already updated the question, is that what you needed? – otong Aug 17 '18 at 17:56
• The speed > 0 condition on returning to idle looks a little strange. Was that possibly meant for the transition to the walk state? – DMGregory Aug 17 '18 at 17:58
• @DMGregory oh yeah, that solved the problem, I forgot to delete the the speed parameter. It used to be integer parameter where I could use isEqual, but then I decided to use float instead. Thank you! – otong Aug 17 '18 at 18:03
• Feel free to add an answer describing your fix then. :) – DMGregory Aug 17 '18 at 18:03

## 1 Answer

Thanks to DMGregory comments that leads to this solution.

Apparently it has to do with the post transition condition. It will play once, but in my case there isn't any valid transition from the playerShoot.

As you can see above, I set the speed param to be greater than 0, that leads to invalid transition when the game object is in idle state (speed 0), therefore the animation stays where is at.