Looping animation while holding key ?

Hey everyone,

I am working on my character blueprint, more specifically on a mining functionality.

When I hold the E key looking at a mineable actor (with some more conditions), my character will start mining for a set period of time. At the end of that period, mining is complete and I will gather the resource.

I have added a handheld mining drill mesh actor to my first person character, and want to animate it shaking back and forth during the animation.

I have my timeline and set position set up properly, I am just stuck at how to properly trigger this.

Since plugging the “on key hold” to start the timeline, just starts the timeline every tick on repeat and it goes crazy.

How should I go about starting the timeline and looping the shaky drill animation, while I am mining, and stopping the animation, while I am not mining?

Cheers

Hey @flossyahova!

You wouldn’t use a timeline for this purpose, as the animation is expected to play for an unknown duration.

Instead of adding those shakes in the blueprint code, I say do it inside your animation sequence by adding curves. You can select the root bone (or any bone of your choice) from the Skeleton Tree window on the top left in a given frame, adjust it’s transform, and hit the Key button with a plus icon on it at the top to modify your animation. Add multiple keys to the frames you like, and there you have a shaking animation!


When it comes to triggering the animation, you wouldn’t use anim montages here, because this isn’t an action such as vaulting, mantling, or punching where it’ll momentarily stop the current animation / play in it’s slot. But if you find it fit for your use case, here’s how you can achieve it using anim montages:

(You can replace the debug key with your enhanced input action of course, and use it’s Started and Completed pins instead.)

To create an anim montage, right click on your animation asset in the content browser, hover over the Create option on the menu that pops up, and hit the Create AnimMontage option under the sub-menu. You can then select your anim montage from the dropdown menu under the Anim Montage pin of the Play Anim Montage node. You can also use the Play Montage node the same way, but if you do, make sure to plug the mesh into the In Skeletal Mesh Component pin like this:

You can get it by dragging the skeletal mesh component from the Components window on the top left into the Event Graph.

Oh and also, make sure that the animation is set to loop from the Asset Details window on the top left inside your animation sequence / anim montage like this:


Now what I’d recommend would be using state machines.

  • If you don’t have an existing animation blueprint, create one by right clicking on an empty space on the content browser, hover over the Animation option, and hit Animation Blueprint.

  • Inside, open up the Anim Graph, then create a state machine (or head to your existing one) and create a new state for your “drilling” animation. Double click on our new state, drag your animation from the Asset Browser window on the bottom right into the graph, and plug it into the Result pin of the Output Animation Pose node.

  • After that, set up a two-way transition between your Idle state (or any other state) and double click on one of those circles with two arrow icons inside. For the transition from another state to our “drilling” state, plug a bool type variable (which you can name something like “Is Drilling”) into the Can Enter Transition pin of the Result node. As for the other transition, drag a NOT node out of the same bool type variable, and plug it that way.

  • Now, open up the Event Graph of our animation blueprint, and after the Event Blueprint Update Animation node, set our bool type variable to another bool type variable which we’re gonna access from the character blueprint. So in your character blueprint, also create a new bool type variable and set it to true after the Started pin of your enhanced iput action for drilling, and set it back to false after the Completed pin.

I know you might be lost somewhere in the long text, so here’s a tutorial on animation blueprints:

Above I linked the 9th chapter where the related topic begins, don’t worry tho you don’t need to catch up on the previous progress to make sense of this chapter. Once you complete that, you can move onto the 10th chapter which is about state machines. Just skip the blend space part there.

Hope these help :innocent:

Hey @VisAgilis,

Thanks for your thorough reply.

This isn’t what I am looking for though. My issue doesn’t come from sequences/timeline/anim montages etc…

My main issue comes from the execution of it.

Since the animation is supposed to play while I am mining which involves holding down a key and verifying some bool conditions, if I just plug my “triggered” interaction execution, it will send a continuous execution order, which spams the animation to play.

On the other hand, if I just plug the “started” interaction execution, I can’t verify bool conditions that happen way down the line in the “triggered” interaction flow.

To make the animation aspect more simple, let’s forget about our fps character, just imagine that there is an object in my FPS character blueprint, on my screen that needs to shake.

Here’s the blueprint pastebin: Mining + animation posted by anonymous | blueprintUE | PasteBin For Unreal Engine

I’m just prototyping for now so it’s very rough but still feel free to comment on whatever you want.

Cheers

You can check the conditions on Started as well, but if you want to trigger the animation after the Triggered pin, you can use the Do Once node and reset it after the Completed pin (where you’d also stop the animation)