Calling `SetBoneRotationByName` but nothing is happening?

Hi, I have been working with Unreal for only the past few days and am trying to rotate a bone in an armature but am having no success.

I used my armature “simple.fbx” in my scene and have added the MyActor component directly to it. I see the category labeled “My Category” and have two variables there, one for assigning the skeleton mesh and the other a vector so I may manually adjust a FRotator that is passed into SetBoneRotationByName for rotating the “Chest” bone.

Despite my best efforts this line just does not seem to work:
myMesh->SetBoneRotationByName(TEXT("Chest"), r, EBoneSpaces::WorldSpace);

Here is my scene and the SkeletalMesh object:

And this is the armature’s skeleton tree:

When I press play I see the UE_LOG printing for each tick, but if I change the values of the myRotation vector I do not see any changes on the armature.

I was wondering if I am doing something wrong with my code. I have very little experience with Unreal but have been trying to follow tutorials as best I can (there are so few good tutorials).

This script took me days to write/understand but I still can’t make it work. Why is the Chest bone of my armature not rotating at all?

Thank you for looking at my post!


#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Components/PoseableMeshComponent.h"

#include "MyActor.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class FIRSTCPPGAMELESSON_API UMyActor : public UActorComponent


	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyCategory")
	FVector myRotation;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyCategory")
	UPoseableMeshComponent* myMesh = nullptr;
	virtual void BeginPlay() override;

	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;	


#include "MyActor.h"

	PrimaryComponentTick.bCanEverTick = true;

void UMyActor::BeginPlay()

void UMyActor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	//int32 numBones = mesh2->GetNumBones();

	FRotator r;
	r.Roll = myRotation.X;
	r.Pitch = myRotation.Y;
	r.Yaw = myRotation.Z;
	UE_LOG(LogTemp, Log, TEXT("Rot I %d"), r.Yaw );
	//DIDNT WORK: //mesh2->SetBoneRotationByName("Chest", r, EBoneSpaces::WorldSpace);
	myMesh->SetBoneRotationByName(TEXT("Chest"), r, EBoneSpaces::WorldSpace);

I realized the issue was due to attaching the MyActor component to a SkeletalMeshComponent object, when i set the mesh for MyActor in the editor it actually created a second mesh instance, but the reason I did not notice it was because my armature scale was 0.01 and so tiny the it blended in with the floor :sweat_smile:

After I imported the SK skeleton and and adding MyActor to it I saw two meshes were overlapping but only one of them rotated as expected.

The solution was to not add the SkeletonMeshComponent into the scene and instead just use an empty object and add the MyActor to it and select the desired mesh.