Download

Best way to change state on animation complete?

Let’s say I have an “isAttacking” boolean my animBP is monitoring. When the user presses the attack button, it changes isAttacking to true, causing the animBP’s state machine to play the attack animation. This boolean is also used to prevent the user from interrupting the attack with other button presses (jump, dodge, whatever).

What’s the best approach to have isAttacking set to false once the animation is complete?

So far I’ve done a few things that work but they all feel clunky and it’s making me wonder if I’m approaching the problem the wrong way. One option is to have a timer in the character BP, but then I have to manually set the time to match the animation.

Another approach is to have an attack montage call an animNotify that’s hooked up to a function that resets the character’s isAttacking to false. So far that the cleanest approach I’ve found but it still feels… weird.

Is there anything better/cleaner?

You can set an OnMontageEnded delegate for the Montage. The montage will call your function when it has finished playing the animation. You can then update any booleans. I do this in cpp with Montage_SetEndDelegate().

State machine Transitions have special nodes (only available in Transitions) that let you get the remaining time: https://docs.unrealengine.com/en-US/Engine/Animation/StateMachines/TransitionRules (near the bottom)

You could use that in the transition rule to set the transition to isAttacking = False AND time remaining < 0.1 or some number you want.