- Home /
Issues with Animator Controller - Trigger does not reset to false after being set with SetTrigger
Edit: Discovered a bit more about this issue. Apparently the issue is only occurring on the host. On the clients, this problem doesn't happen.
I still don't understand why it's getting triggered twice when it's only being triggered once.
Original Post:
I have been trying to solve this issue for a while now and I've eliminated a number of faults which could possible occur. In the animator, the trigger "attack" is set to true and stays true until the animation is called a second time, resulting in the desired animation playing twice instead of once like it should.
I understand that a trigger will stay true until it's used in the Mechanim animator, howeever it is used. It is used as soon as it is triggered, starting the first animation. Once the first animation is played, it then returns back to the idle state and the trigger starts the animation again, after which the trigger is set to false.
This isn't how it should be working and I'm currently stumped trying to figure out what is going wrong here. I'm currently using Unity 5.6.1p1.
if (attack && !swinging) // Stops playing from starting a new attack when they're already attacking.
{
if (attackTimer >= attackRate)
{
swinging = true;
attackTimer = 0f;
playerAnimator.SetLayerWeight(1, 1); // Set's the layer for attack animations to 1.
dealDamage = true; // Tells collision detection that damage can be dealt
canCombo = true;
networkAnim.SetTrigger(attackHash);
}
}
This code is what triggers my attack animation. Once setTrigger has been called, it cannot be called again until "swinging" has been set to false, which is done by checking the value of a curve attacked to the attack animation.
I have even changed my attack input from Input.GetButton to Input.GetButton down to ensure there is absolutely no possibility that the trigger is being set to true after the the animation has started, which was technically already being done by stopping the player from starting an attack when the bool swinging was already true.
I'm really at a loss to figure this problem out and I've read a tonne of posts from people having the same issues.
I've tried some of the solutions that people have offered but they haven't worked, and I'm slightly frustrated that I need to manually reset every trigger for every possible transition, when the whole point of a trigger is that once it's used, it automatically resets to false.
If anyone could assist me with this issue I'd be extremely greatful.
If I can't resolve this issue I'll probably start by rebuilding my animator controller from scratch, and if the problem reoccurs then I'm not sure what I'll do.
until "swinging" has been set to false, which is done by checking the value of a curve attacked (sic) to the attack animation.
Not sure I follow but since the trigger in question has "attack" in its name, perhaps is this saying that "swinging" gets set to false while the animation is still playing? If so then perhaps you're triggering again before the trigger has been consumed (I don't believe it gets reset until the end of the animation that it's triggered).
Answer by Marshal_Alessi · May 26, 2017 at 07:30 AM
Not sure why you're experiencing the issue, but maybe try putting
networkAnim.ResetTrigger(attackHash);
in your update function, so that it resets it automatically. Hopefully this will fix your issue!
Not really a solution to the problem at hand - more of a work-around.
I'm trying to figure out why the trigger isn't acting like it should in the first place.
Answer by Pranky · Aug 30, 2019 at 10:31 AM
You can try following function
void AnimTrigger(string triggerName)
{
foreach(AnimatorControllerParameter p in animator.parameters)
if (p.type == AnimatorControllerParameterType.Trigger)
animator.ResetTrigger(p.name);
animator.SetTrigger(triggerName);
}
Your answer
Follow this Question
Related Questions
Animation begins at start of Gameplay before colliding with trigger 2 Answers
Play animation from animator? 1 Answer
Animation that is triggered with a ui button doesnt play on android build 1 Answer
How to smoothly change from opening a door animation to closing a door animation 0 Answers
How do I setup a Shooting Trigger to make an Animation play on a Platform? 0 Answers