Revert player back to original animation after playing animation on overlap


Im trying to play an animation when a character overalps with a mesh. The animation plays but how do I revert the character back to its original animation. I want the animation to be a knock out so when the character get hit it cant move for a while, but then goes back to its original animation. For now, however, Im using the crouch animation to represent my knock out, and my crouch animation already as transitions in a state machine to go back to walking.

Honestly? I would probably take your ThirdPersonCharacter class and make a “StunForDuration” function on it that took a parameter of how long the character should be stunned for, then:

  1. When you overlap, call StunForDuration on the character, with the appropriate duration for that particular overlap volume. (Bonus: different instances of the overlap volume could stun for different durations!)
  2. The ThirdPersonCharacter sets a “StunnedUntil” value (the current time + the stun duration), as well as a “Stunned” boolean value being set to true.
  3. While Stunned is true, the ThirdPersonCharacter ignores all movement input.
  4. While Stunned is true, the animation blueprint for your ThirdPersonCharacter will just play the stunned animation sequence.
  5. In the Tick handler, your ThirdPersonCharacter checks if the current time is greater than the StunnedUntil value; if it is, set Stunned to false.
  6. When Stunned is no longer true, hey, your character takes movement again and also the animation blueprint resumes its proper state.

(That said, there are probably also more elegant ways to do this, depending on how you’ve set up your game.)

“play an animation” and “affect gameplay” are two totally different things.

To play an animation, which overrides the animation blueprint, and then goes back to the blueprint behavior, add a “Default Slot” node right before the “final output” part of the animation blueprint. Then, to play an “override” animation, use the “Play Slot Animation” in the “Default” slot to play the animation.

To stop the character from reacting to input, you need to create an “IsStunned” flag in the Character (or Player Controller, if you use that) and wire each input event to test this flag, and do nothing if it’s set. Then, when stunning, set the IsStunned flag, set a timer for your stun duration, and make the timer call an event that un-stuns the character. If the timer is already valid, cancel it and re-set it, so that subsequent stuns lasts until the last one has had its full effect.

If you have IsStun on the Character, you COULD also make your animation blueprint state machine check for this state, and transition into a “play stunned” animation, until the flag goes off again, and it transitions back. If you do this, you don’t need the “play slot animation” override, because your animation blueprint instead inherently knows about stunning. Which option you prefer depends on gameplay and art goals.

1 Like

Could u show example plz

Without knowing how you have your player and animation blueprint set up, not easily. Or rather, it would be possible to make an example project, but it might be doing things in a fundamentally different way than your existing game content is.

How to inhibit movement when stunned flag is true:

How to set stun flag for a certain amount of time on overlap (you probably want to test WHAT you’re overlapping with, too):

Playing the “stun” animation when getting stunned:

Add default slot to the animation blueprint:

Also, in this illustration I forgot to tick the “true” button for the “set is stunned” node. You’ll want to do that to actually make the character take the “stunned” path :slight_smile: