Attack Trigger never resets, Animation gets stuck, never loops

So, SetTrigger works, but the attack trigger never resets and I have no idea if it will actually respect ‘timeBetweenAttacks’ because it’ll never play the animation more than once. Isn’t the trigger supposed to reset automatically with Unity?

There are certain conditions that cause the trigger not to reset… one example is calling the trigger when there is no applicable receiver for the trigger… this can happen if you SetTrigger(“Attack”) before the attack state has finished.

The solution is simple: Whenever you set a trigger, first reset the trigger immediately before setting it.

animator.ResetTrigger("Attack");
animator.SetTrigger("Attack");

Well that sorta helped. Now the “attack” trigger isn’t permanently set. But even with the attack trigger not set, the player never returns to the idle state and the attack animation still never plays again.

I’m staring at the Animator and the attack trigger never even gets checked. I’m thinking something may be wrong with the animator itself? But I’m also using Unity 2022 and I’ve expected this course to blow apart at some point.

Never mind the code did nothing at all.

Nothing’s changed on the Animator in Unity2022…
You should have two transitions from Attack to Idle
One should have no conditions with Has Exit Time checked. The other should have a condition of StopAttack with Has Exit Time unchecked (unless you haven’t gotten to that lecture yet).

Is your Player setup with all the scripts on a GameObject (including Animator) with a child object that’s the model that also has an Animator? If so, delete the Animator on the child object, it sometimes interferes with the Animator on the root of the player.

The entire chunk of scripts is on top of the Player object.
image
I removed the animator from the child object that is the model.
image
But unfortunately, nothing changed.
If StopAttack was supposed to be a condition I needed in, it wasn’t mentioned in this lesson or any previous ones as far as I could tell. Was it supposed to be a trigger? Boolean? In which of the scripts was that supposed to go? Because I don’t think Sam would wait until the Taking Damage lesson to put in something that actually makes ‘timeBetweenAttacks’ actually function. Because… for some reason, it isn’t as is.


Somehow, the StopAttack is never mentioned or even used by Sam but it just… works as intended. I’m beginning to suspect black magic?

StopAttack will be used in a later lesson… Stop Attacking Already… when the target is dead.

If you’re not to that lesson yet, then the only transition from Attack to Locomotion should be one with the Has Exit Time checked and no other condition.

Privacy & Terms