- Home /
Animator: Trigger not reseting, bug?
i was following the 2D roguelike training....The guy said the trigger is almost like boolean, but it reset to default after click. in my case, my trigger is exactly what boolean does. how to fix this? I'm using unity 5.0.2f1 personal
what you mean? when I compile the game with animator open so I can click the animation to animate the object, it change to other state as long as I clicked it. just like boolean, it changing from 0 to 1, but I have to click one more time to change it from 1 to 0. As in tutorial, he clicked the animation and return to 0 by itself (also, I would like to mention that the shape of the button is different, $$anonymous$$e is circle, the video is a block) but I already make sure that I'm using trigger, ins$$anonymous$$d of others.
Answer by georgeq · Jun 09, 2015 at 12:49 AM
This problem occurs when you set a trigger when a transition is still in progress. You code is generating a situation in which playerChop is triggered before the animation started by playerHit has ended... or playerHit is triggered for a second time before the transition started by the first trigger has ended. Use triggers only if you are sure the animation will play full, from begginig to end, before issuing another trigger... otherwise you will end up patching your code like this:
animator.ResetTrigger("playerHit");
animator.SetTrigger("playerChop");
.
.
.
animator.ResetTrigger("playerChop");
animator.SetTrigger("playerHit");
Answer by memoid · Mar 12, 2017 at 05:51 PM
Yes I've come across this problem too (in Unity 5.5), and google is full of people asking about it! Like people say, the issue is that the Trigger stays on until a State transition needs that particular Trigger. E.g. if you are in State A and you Trigger a parameter which is for a transition from State B, it will stay on until we are in State B.
You can use Animator.ResetTrigger to clear the trigger. In small situations this is manageable, but in some situations I've found this to be a PITA.
E.g. I have a matrix of states with lots of transitions between them mapped to keyboard shortcuts. States A, B, C, D, E, F. And transitions A->B->C->D->E->F as well as A<->B, A<->C, A<->D, A<->E, A<->F etc. (Think of it as 'Next State', 'Go Home', and 'Jump to State').
Generally it works fine, but if I press a keyboard shortcut for a transition which is unavailable (e.g. the keyboard shortcut for A->D, while I'm in state C), then that Trigger stays on until I go to A, and then it immediately jumps back to D. Which is not what I want! To manually code in each of the ResetTriggers for each of the states etc would be a pain, so I've written the little function below to first clear ALL triggers, and then set the desired trigger.
void AnimTrigger(string triggerName)
{
foreach(AnimatorControllerParameter p in animator.parameters)
if (p.type == AnimatorControllerParameterType.Trigger)
animator.ResetTrigger(p.name);
animator.SetTrigger(triggerName);
}
A more efficient way to do this would be to save all the trigger names after getting the animator (probably in Start), then to use those saved values instead of rechecking for them all again every time you call this function. Not sure if it matters with what whoever is reading this is doing, but figured it was worth mentioning! :)
Answer by jezzaboy · Jan 25, 2019 at 09:18 AM
For those following the 2D roguelike training, clicking your "player" in the hierarchy will fix the issue and show the auto live link like in the video.
This worked for me! Reselect the thing you are animating in the scene view. This really looks like a bug to me.
Thanks man it worked. Just first selecting the character who has animator controller on him, then testing the triggers worked
Answer by yourecrippled · Mar 17, 2017 at 02:25 PM
animator controller > click on state > uncheck "write defaults"
I did this to all states in my animation controller. It worked for me.
I'm suffering the same issue and this didn't fix the issue.
worked for me with 2018.3.14. seems like a bug since afaik "write default" affects the default value for properties of gameobjects being animated, not parameters like triggers https://forum.unity.com/threads/write-defaults-confusion-bug.392058/#post-2565600
Answer by Bliko · Dec 01, 2017 at 10:20 PM
Had same problem as OP. I exited unity which prompted me to save, I did, and when I reopened the triggers were resetting, and also under the states I could see the bar filling up as the animation plays through, which I couldn't see before.
Your answer
Follow this Question
Related Questions
Parameter does not exist 3 Answers
Animator Condition Not Working 0 Answers
Why is my character not flipping? 2 Answers
How to avoid double trigger behavior? 0 Answers
Animation Keypress Trigger Problem 0 Answers