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.
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;
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.