Why does the animation not play only when spam clicking?

My mistake, thanks for pointing it out.

Hello, I am having a bit of an issue with when my player can and can’t attack. I attached a screen capture of the player blueprint.

The problem is that if I spam click the attack input multiple times for a long time, even though the delay passes and the conditions are reset, my player does not play the animation for a second time as long as I keep clicking fast enough. If I wait for a moment and click slightly after the delay, it works fine.

Problem is, if a player is spam clicking, it would be natural for the attack to fire when clicking after the delay is over, but instead the animation just does not play unless waiting for a long enough time between each click. It feels very non-intuitive, because sometimes an attack simply won’t fire because you clicked too soon, and if you spam click to compensate, it actually takes longer because you have to stop spam clicking and then wait long enough before clicking to make the animation play again.

If I add a 0.2 second delay node before the “IsAttacking” variable is set to true (this variable transitions the player to the attack state in the animation blueprint), I can spam click and the attack will always fire right after the “IsAttacking” variable is reset back to false after the 0.75 delay. Problem is of course, that adds a delay to the attack input, which messes up the gameplay. I tried making the 0.2 delay shorter, but then I get the same problem mentioned above.

I’m stuck on what to do. Any help would be greatly appreciated, thank you.

You forgot the blueprint… :wink:

I’m just going to ask a dumb question here, but what’s playing the animation?

So, it starts playing the animation every time you set the bool? Then try a retriggerable delay.

The IsAttacking boolean is being casted from the player BP to the anim BP, transitioning between the states in the state machine.

That’s right. How would I go on about using a retriggerable delay for this?

BTW: I can see that in the state machine, after the attack delay is over and the boolean is reset, it returns to the Idle/Running state. If I click attack again right after it changes back to Idle/Running, it goes to the Attacking state, but no animation gets played. Unless I wait an extra moment during Idle/Running before clicking again.

Just:

332912-screenshot-1.jpg

Tell me how it goes with that. Otherwise, we put an extra bit of logic in…

I tried, but there’s no noticable difference.

Hi, there are definitely some things we can improve here. First of all delay nodes are evil, try not to use them. Since we work with animations and states, I’d move all logic into the Animation Blueprint and give the State Machine full control over when state “attack” starts and ends. Then you wouldn’t need to mess with delays in the first place. The correct steps would be :

  • Player presses button : attack > sets a bool on the animation blueprint to “AttemptAttack”
  • The animation state machine moves into state “Attack” on AttemptAttack
  • An animation plays. when the animation is nearly finished it goes back to idle automatically. You can get this bool by doing (“Get relevant anim time remaining *” < 0.1) which gets the remaining duration of your attack animation dynamically.
  • If required, any state transition or event of entering/leaving a state can trigger an event on the EventGraph of the Animation Blueprint so you can put more logic in there as well.

That way you keep all logic in one place and no delay will ever mess up your intention.

Maybe this, but could be wrong: