Trigger an Animation inside State Machine

Perhaps I’m not understanding this as well as I should, but would like to have an animation of a character trigger either through a key or a touch event that would play the animation and then transition back to the Idle/Walk inside of a State Machine. I was able to get the animation to play when added to a Blueprint only, however once the animation played, it wouldn’t idle/locomote again. I figured if it was part of the state machine, it could have a way to transition smoothly back to it’s main state again. If what I’m thinking is correct, how could I get that work? Any examples or links to sources would be greatly appreciated.

There’s nodes that will tell you if a key was pressed. You could create a new state with a transition rule that checks if “___ was just pressed” is true. Or you could set a bool on the key press and use that as the transition rule. For the transition rule back to idle you can just use asset (animation) time remaining < .1.

Thank you for the reply. I’m probably doing this wrong, but I included screenshots of my Character Blueprint, AnimEventGraph and the AnimBluePrint. Still isn’t working, but maybe there’s something you might notice.

Have you tried to debug this by Print Strings etc?

I am not on computer so I can’t check what’s wrong with the Anim BP. Showing whats inside BasicAttack and Idle/Run might be helpful aswell.

Make sure the casts are not failing.
Put some print strings to check if the value of “Is Basic Attack? Anim NP” is changing from true to false and vice versa everytime you press that button.
Also check how long does it take to make the transitions between each state. Maybe it’s all working but the blending between has too long time between etc. =)

In addition to checking the cast and the value of that bool, can you tell us what your transition back rule is?

Achilleon - I haven’t tried Print Strings, that’s a great point, going to add those today. Here is what is inside Basic Attack and Idle/Run.

MuchToLearn - I attached what the transition rule for going back to the Idle Run.

Thank you very much for the replys!

Don’t you need the ratio to be greater than 0.1? Right now it will only play for 10% of the animation duration and then blend back.

Your rule is checking if the ratio of time remaining is greater than or equal to .1, you need to do less than. Your current rule is going to return true as soon as you move to that state. When the animation first starts, the time remaining ratio is going to be 1. So it’s going to transition back immediately. You want to check and see if the remaining time is less than .1. I’d use the one based off of time instead of the ratio too.

Denny/MuchToLearn - Yeah, that was my goof, thanks for the double-check.
Achilleon - The Print Strings definitely helped out, so it allowed me to debug what was actually working.

So here’s the update:

First and foremost, I probably should’ve mentioned that this was based off the Top Down Template.

  1. Reviewed the Inputs to make sure the key bindings were set up to the right keys.
  2. Added Print Strings to the InputAction Basic_Attack. The weird thing is that when these were present in the Blueprint Class, it was unresponsive. When it was added to the TopDownController BP, it worked and could see the strings being drawn. Unfortunately the animation did not play.

  1. Updated the Event Graph. Added the Print String at the end of the isBasicAttack? Set. When I run the simulation, the string spams the left side of the string continously. When I hit the attack button, I see the commands appear amidst the spamming string from the Event Graph.

  1. I updated the State Machine based on what you’ve recommended. The character simply idles, however, if I click on the check box in isBasicAttack? the character will play the animation once and just sit there.


Again, you guys have been great and really appreciate the advice. So far, I feel that it’s creeping forward, my assumption is that there’s something wrong with the EventGraph.

Resolved. OK, first off, again, thanks for the help. I realized that from starting this from the Top Down Template could be adding all sorts of hidden settings that could be causing me issues. So I started a Blank Project, selectively merged my assets in and rebuilt the Blueprints, which is exactly like the above - with the sole exception being that the Input Action is now in the Character BP, not the Controller BP and it works and transition exactly how I wanted it to.