Animations in pure C++ (no blueprints)

For last month or so i am in a contest of kicking with horse called “animation blueprint” in unreal. There are multiple problems involved, but somehow i can push this forward. I am near competition of animation blueprint for first character. However what i realized just yesterday, is that for next character (different skeleton proportions) I need to retarget all animations and recreate animation blueprint (which is quite complicated). For total of 4 hero characters and some (much simpler) enemy animations. From experience i know that there will be bugs and changes in code, I kind of hate thought of maintaining 4 separate versions of code that does exactly same stuff. Blueprints are dead bent on single skeleton, cannot do same blueprint for different skeletons (or maybe i am missing something here).

So i have some questions:

Is it possible to create pure C++ code for handling animations for player character? That includes using blendspaces, montages, aim offsets and IK.
Is it possible to create such code for different skeletons? That it will work for all of my characters that use same skeleton but different proportions.

If above is doable, where i can find any documentation or tutorials. My problem here is that all tuts about C++ and animation show how to code character movement in C++ then use animation blueprint. And are mislabeled as animations in C++.

So where do i start with pure C++ animation code in unreal?

No. You can write the event graph in code, but you can’t make the anim graph in code because majority of functions there are protected or private to anim graph classes.

Thank you Xavier for reply.

BTW - I am sure you already realize this, but if your characters are all similar ( eg humanoid ) they can still share the same skeleton and the same animation blueprint.

Even if they have different dimensions and sizes, as long as they still have same bone hierarchy.

I have 2 female and 2 male models. They have different distances between clavice bones.
Clavicle bones get messed up (in some animations) when i retarget (assign) models to same skeleton.

Bit more explanation about reasons for my asking:
I also hoped that, next (after this C++ only animation) would be plugin inspired by this speech about procedural animation:

With it (in C++) i could have easy way to drive all animations for more than single project. Its possible to do in blueprints, but then swapping skeleton for complicated system like this is kind of more work than coding it from beginning.

I wanted to keep my original question simple, until i know if that was possible at all, and as i suspected it is not. Well i suspected its quite hard, not impossible without changing half of engine.

When you import them, import onto your existing skeleton.

In UE, skeleton==bone hierarchy.
With this setup, you only need one AnimBP.
There is no need for separate skeletons in your case.

You can control how these different sizes are applied on a bone by bone basis in the skeleton retargeting options. (This is Same Skeleton Retargeting) Animation Retargeting | Unreal Engine Documentation

BTW - The existing AnimGraph Nodes can do accomplish a ton of stuff … but you can also write additional anim graph nodes in c++ if you want.

I tried to import male character onto skeleton (and animations) made for female, it did not go well.
Maybe because i did not modify those settings for bone transformations.

Also there is no point in using C++ when you need to pipe all results trough C++ anyway. IMO. C++ has only 2 benefits, that is speed (so i use it for heavier tasks), and ability to close all code into one single container that will not get accidentally corrupted like blueprints love to do. Cant do that C++ only module approach for animations, and that task (Animating) will not benefit much (in speed) from C++.

Ideally, you only need 1 skeleton, 1 set of animations, and 1 AnimBP.

Starting from scratch… import the female and all animations. Create the AnimBP. Import any additional skeletal meshes, but be sure to select existing female skeleton and dont create new one.

You can use the skeleton tab of persona to set retargeting per bone: A common starting point is

  1. Right-click on your root bone and Recursively Set Translation Retargeting Skeleton so all bones are set to Skeleton.
  2. Find the Pelvis or equivalent bone and set that to AnimationScaled.
  3. Find the Root bone, any IK bones, any weapon bones, or other marker-style bones and set them to use Animation.

btw- Another benefit of the animgraph is you can leverage the FastPath to utilize parallel pose evaluation. This uses multiple cores to evaluate the bone pose for each animation. Evaluating the pose is expensive and costly… especially when you have 100 zombies to update every frame :wink:

Thanks i will try this, apparently i am missing something with importing (making it work properly) male models. TBH, I just imported that model once, seen its distorted and then i focused on making female hero animation blueprints as it has additional physics based animations.

And for zombies\enemies i will not create complicated animation blueprint, like i am doing for player character.