How to effectively play an animation on click?

K im making a character that will play a swing animation on left click, i set a bool to true that is used in the animblueprint to start the transition to the swing anim, once the ratio of the anims completion is less than 0.2 i transition back to the idle anim. once completely i set the bool to false so that it wont cycle back into the attack anim… this works.

but… ive noticed a delay, i small window of time where the swing animation is finishing up (probably within that 0.2 ratio) so obviously the bool is false at this time, so if i click at this particular time it sets it to true and it does the other functionality of the swing attack but doesnt play the animation because the previous animation is not finished yet.

when setting the ratio completed check to 0.05 it stays in the attack state indefinetly, if i trigger the setting of the bool off of the “END” of the transition it stays at the last frame of the anim and never goes to the idle state.

has anyone made a fool proof click triggered animation? am i doing this just horribly wrong or what?

You may want to try using an AnimMontage for your swing animation. It will allow you to take all of that logic out of your state machine and basically just play your swing animation over whatever else is happening. There’s a pretty thorough tutorial for setting up an attack using montages in the documentation here: LINK. Note, in that example, they are setting up the animation to only play on the character’s upper body, but you can just as easily play the montage on the character’s entire body by not filtering the output of the Slot node with a LayeredBlendPerBone.

Good luck, and just yell if you have any other questions/issues.

holy crap two awesome answers in a row, thanks man.

just barely saw the new mention of animmontage on the front page, zeitgeist!

thanks again man. :slight_smile:

Sorry if I am bumping up a resolved problem. I am trying to follow along that tutorial you posted Ray, but I am having problems with the section “Setting Up the Event Graph”. I don’t really understand the part with the blueprint interface, and how it would look/work. Any chance of getting some help here? thx

Sure, I think I can clarify that a bit.

First, you’ll need to create a Blueprint Interface (Rt-click in the content browser, go down to Miscellaneous and it should be at the top). Then add a function to your Blueprint Interface. You’ll use this to trigger the event in your AnimBP EventGraph (I think they called it ‘startAttack’ or something in the Montage example). That’s it for the Interface!

Next, you’ll need to implement the BP Interface in your Character BP. Do that by clicking on Blueprint Props up in the toolbar, Then, in the properties panel that pops up, under Interfaces, add the Interface you just created. You’ll then use that interface and function to send a message to your AnimationBP by getting the Mesh (Get Mesh), getting the mesh’s Anim Instance (which will give you its AnimBP in this case), and then sending a message using the function in your Interface. Like so:

Finally, you’ll need to implement that Interface in your AnimBP just like we did for the Character BP. After that, you should be able to use the function from your Interface as an Event to trigger whatever you want to do. Like this:

Note, in my example, the name of the function in my BP Interface was ‘DoSomething’.

Hope that makes things a little clearer!