How can I rotate Bones Purely In C++?

Hi! I’ve seen a lot of examples on here about how to rotate bones in a skeletal mesh, but all of them involve BPs in some way. Like this one: How to rotate bone in C++? - Programming & Scripting - Epic Developer Community Forums (You rock, !) - I want to avoid this.

Does anyone know how to rotate a bone without using the BP nodes? I tried looking them up, but I couldn’t find the code in the BP Node class, all it has is text describing the node.

I had a look at the UPoseableMeshComponent, but that cannot play animations. Basically, here’s my situation: I have a turret. It has 3 components (not actor components,) a base, a body and a barrel. I want to rotate the barrel and body dynamically, based on what’s going on in game. However, the turret also has a couple of animations, ‘wake up’ and ‘sleep’, that play when it’s restocking its ammo. I can do the former with the Poseable component and the latter with the Skeletal Mesh component… but not both.

Is there a class I’m missing? Something like a character model component, where the body can play animations, but the head can be set to different angles, etc., but all in the same mesh. Maybe I can do it with the BlendSpace animation asset? But how do I use those? And what component class would I use with it?

Anyway, any help appreciated, thanks.

TTaM, did you ever figure out how to do this? I am looking to do the same.

Yeah. You need to use a Poseable mesh. You can’t rotate the bones (directly) of a regular skeletal mesh. Using a poseable mesh means you can’t play animations, though.

Got it, thanks. But you know, it really seems as though what suggests regarding using Skeletal Controls should be possible to do all with C++. After all, blueprints are just C++ classes/code with some extra info so that it can be used by editor. That is, there really shouldn’t be any blueprint classes that couldn’t be called from C++ directly in principle.

Yeah. I looked up the source code for the nodes that rotate bones… but no idea where the actual code is. The “node” class just describe the actual node, not contain the code for what it actually does… Or maybe I missed something somewhere. I was looking at a simple node, too, like the float addition one. Nowhere in the node class was “some float + some other float”. Maybe that’s just too easy…!

It seems that PoseableMesh does what I want for now, however, TTaM’s original question here still stands. It would be useful to know how to do that too.

Hi TTaM and dekrat,

I apologize that we missed this question. Were you able to get this working for what you needed?

Hi . Thanks for the response. I haven’t touced this particular problem since posting this thread a while ago. The original question of how to have a skeletal mesh in c++ that can both be poseable and play animations still stands.


I spent some time going through some of the source code today and wasn’t able to find anything specific that might help with this. I have reached out to one of the developers to see if they may have some insight into how this could be done.

We don’t provide multiple ways to manipulate bone for one instance, that will cause problem with consistency.

The best example you can look at is UAnimPreviewInstance. This is used in editor for Persona when you modify bone transform in viewport, and it has list of ModifyBone Controllers and use that to manipulate. You can create your custom AnimInstance and then apply those transform from native.

I think that’s probably the best way to do this. I still recommend using normal skeletal controls.

This is the blog I wrote a while ago about modifying bone transform.



Thanks a lot for the reply. I’ll look into it :slight_smile:

Hi ! I know its been a long while but did you find any solution for this after talking to the devs? I want to implement what TTam posted, would be glad if I could get some help.

I managed this by reading out the Animation (At a given time) from UAnimSequenceBase and fill a FCompactPose with it. Then u can set poseable mesh bones with the values from FCompactPose :slight_smile:

this should give u an idea:

FCompactPose Pose;
FBlendedCurve Curve;
InAnimSequenceBase->GetAnimationPose(Pose, Curve, FAnimExtractContext(InTime*InAnimSequenceBase->SequenceLength, false));
for (FCompactPoseBoneIndex BoneIndex : Pose.ForEachBoneIndex()) {
// Animation BoneSpace to WorldSpace
FCompactPoseBoneIndex ParentBone = Pose.GetParentBoneIndex(BoneIndex);
    			if (ParentBone.GetInt() != INDEX_NONE) {
    				Pose[BoneIndex] *= Pose[ParentBone];
    			else {
    				Pose[BoneIndex] *= InPoseableMesh->GetComponentTransform();
    			}   .......