3rd person template code for playing run/walking animation?

Hi,

Can someone tell me where exactly can I find the code for the running/walking animation that’s being used in the 3rd Person Template? I saw the template has a MoveForward(float Value) function, but the code to play the animation of running isn’t there…

Thanks

P.S In fact, if someone can tell me how to actually code the animations based on what key is pressed is even better :stuck_out_tongue:

All animation is controlled via an ‘AnimBlueprint’. If you filter by that in the Content Browser there should be just one in the template, and you can open it up and see how it grabs information from the Pawn in the Event Graph and then uses that to blend animations in the Anim Graph.

This tutorial uses a first person mesh and animations, but you can see how the animations are set up, which may help when following along with the AnimBlueprint in the template that James mentioned. :slight_smile:

Thanks for the replies :). So just to make sure - basically there is no way to purely hand code this? I MUST use these Animation Blueprints?

You can call the animations from code as well. Search for the PlayMontage function.

Easiest is turn your animation clips into Montages, that is done in the Editor, then in the controller Blueprint have references to the Montages that you call in code, set the references in the Editor by dragging them on.

I don’t have my project available right now so I can’t show an example. But I call Montages from code. In the tutorials section there is a thread on Behavior Trees, if you look in there I left the functions that called and stopped functions even though it didn’t have to do with Behavior Trees exactly. It includes the references to the Montages.

Hi Danny-sama,

The anim blueprint creates a subclass of UAnimInstance, which is placed on the USkeletalMeshComponent. You can play ‘one-off’ animations from C++ using AnimationData on the component without making an Anim Blueprint, but you won’t be blending between multiple animations in that way.

The system wasn’t really designed to build an animation blend tree entirely in C++, although it should be possible.

Note: This is theoretical, I’ve never tried to do this before, but it’s basically doing by hand what the anim blueprint compiler does.

Create a subclass of UAnimInstance, add whatever FAnimNode subclasses you want to it as member variables, and then override InitializeAnimation to wire up the pose links and set RootNode as desired. The rest of the code should ‘just work’ from that point.

If you’re just worried about C++ being able to control the direction of animation, there are a number of options. You can make your own UAnimInstance derived class that gathers parameters or chooses animations and make an anim blueprint based off of that, or you can do most things in the anim blueprint and still trigger override animations on specific slots in the tree using PlayAnimMontage or PlaySlotAnimation.

Cheers,
Noland