Manipulating animations through code

I want to manipulate animations on a very low level through C++ code. I want to be able to step through the animation key frames one-by-one and perform operations on the bones between frames. I have looked over the forums and the Answerhub and have been unable to find any clues or examples.

So does anyone know a good place to start or have any information on this topic?

This is not entirely done in C++, or at least not the intended way for you to do it. Here is an example where I get to control the bones of a Chariot in C++.

First the declaration of variables I will use to transform the bones. In my case those are rotators and the speed of rotation from the wheel of the chariot. In your case, you can have whatever you want, like FVector if you want to translate the bones.

protected:
	UPROPERTY(BlueprintReadOnly, Category = Chariot)
	FRotator mShaftRotation;
	UPROPERTY(BlueprintReadOnly, Category = Chariot)
	FRotator mAxleRotation;
	UPROPERTY(BlueprintReadOnly, Category = Chariot)
	float mFrontWheelRotationSpeed = 0.0f;
	UPROPERTY(BlueprintReadOnly, Category = Chariot)
	float mRearWheelRotationSpeed = 0.0f;

One this is done, you need to create an animation blueprint that will be linked to your skeletal (here I’m guessing that the class you are working in is the one holding the SkeletalMeshComponent, at least it should be!). You can do that in the Animation category of your SkeletalMeshComponent. Here:

30290-linkanimbp.png

Once this is done, in your animation blueprint, you will want to create variables that are the equivalent of what you have in your C++ class. After doing so, at each frame you will have to get the values you have set in the C++ class and assign them to the Anim BP corresponding varaibles in the Anim BP Event Graph. Like so:

After that, this is where you will actually transform your bones. In the Anim Graph of your Animation Blueprint.

To do that, you need the Transform (Modify) Bone node. Like so :

Notice that the node has a lot of options. You first select the bone to modify and then after that you can choose what kind of transform you want to apply. Be very careful of the Mode of transform you choose. By default it’s set to BMM Ignore, which just ignore your transform! So you want to either choose BMM Replace or BMM Additive depending of what you need.

You could probably achieve the whole thing all in C++ by creating your own AnimInstance and setting a lot of stuff up but this is (I think) the easiest way to do it.

Good luck!

Thank you Michaël for the very detailed answer. I think this is enough to help get me started.