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
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");
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);
}
animator controller > click on state > uncheck “write defaults”
I did this to all states in my animation controller. It worked for me.
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.
I recently ran into this issue when using a single jump trigger and managed to fix it: The transition into the triggered animation needs to have the condition set to the trigger (obviously) with “Has Exit Time” set to FALSE as this makes the timing buggy. In addition, the triggered animation then needed to transition back to the previous state with NO CONDITION but with “Has Exit Time” set to TRUE (so, the opposite of the transition in basically). If the option is set to false the animation would play to the last frame and then stay there, and nothing would budge it.
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.
Should this be of help, I had to re-check “Has Exit Time” in the transition. (I always disable it because so far I have had too to remove UI delay)
In my case, the return transition was not given, I.e., the transition from final animation clip to initial clip in the animator. Try to make a transition and add the same Trigger parameter to it also. It works for me… hope it will help you too…,In my case, actually the reverse transition was not given, i.e., from the final animation back to initial state… Try this it may work for you too…