# How to rotate bone in C++?

**URL:** <https://forums.unrealengine.com/t/how-to-rotate-bone-in-c/284161>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 24, 2014, 11:25pm UTC](https://forums.unrealengine.com/t/how-to-rotate-bone-in-c/284161 "2014-05-24T23:25:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![noatom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@noatom](https://forums.unrealengine.com/u/noatom)\
**Post date:** [May 24, 2014, 11:25pm UTC](https://forums.unrealengine.com/t/how-to-rotate-bone-in-c/284161/1 "2014-05-24T23:25:01Z")

</div>

So, how would I go about rotating a bone in a Skeletal mesh?

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 25, 2014, 1:06am UTC](https://forums.unrealengine.com/t/how-to-rotate-bone-in-c/284161/2 "2014-05-25T01:06:37Z")

</div>

![6964-movebonefromcpp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/b/6/bb6f7afb3d72c08bc91e962cf2a88629c3fa2af8.jpeg)

In this example above I am rotating a single bone from CPP which controls the creatures torso twist.

#Custom Animation BP

Make a custom Anim BP class (AnimInstance.h)

Make custom c++ variables for each of your intended ways of manipulating bones

Make Skeletal Controller Nodes within your custom Animation Blueprint

Attach your custom cpp variables to the Animation BP Skel Controller nodes

now you have the interface for adjusting your skeleton in cpp, but being able to preview settings inside the editor for visual confirmation of whether you have the right axis/direction in mind.

#Wiki Tutorials

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

**Anim BP Custom Logic via CPP**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Rama

---

<div class="post-metadata">

**Author:** ![TiagoLing](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TiagoLing](https://forums.unrealengine.com/u/TiagoLing)\
**Post date:** [July 27, 2015, 2:51pm UTC](https://forums.unrealengine.com/t/how-to-rotate-bone-in-c/284161/3 "2015-07-27T14:51:35Z")

</div>

How would you go about setting the “Torso rotation” in C++ code? I’m trying to do the same but the bone is acting weird when i move the actor.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_34c406be](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_34c406be](https://forums.unrealengine.com/u/anonymous_user_34c406be)\
**Post date:** [October 15, 2017, 1:27pm UTC](https://forums.unrealengine.com/t/how-to-rotate-bone-in-c/284161/4 "2017-10-15T13:27:52Z")

</div>

@Rama I want to do this for all skeletal bones. Here I have realtime motion capture data from a custom made system which has 17 bones. I just want to implement these data in a skeletalmesh. As you have mentioned before do I need to create 17 “Transform(Modify) Bone” functions to do this? And how to get each bone reference to this function?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_006f1178](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_006f1178](https://forums.unrealengine.com/u/anonymous_user_006f1178)\
**Post date:** [October 1, 2020, 6:06am UTC](https://forums.unrealengine.com/t/how-to-rotate-bone-in-c/284161/5 "2020-10-01T06:06:35Z")

</div>

Hi I found a way to manipulate one single bone of my vehicle using only c++ here is what I did :  
the bones I want to manipulate is the front wheel of my vehicle ; “Wheel\_Front\_Left” and “Wheel\_Front\_Right”, I want to rotate it with a given angle  
all what you need

//1. NormaleCar.h

```
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"

#include "Components/PoseableMeshComponent.h"
#include "NormaleCar.generated.h"

class UPoseableMeshComponent;

UCLASS()
class RECVCREATEVEHICLE_API ANormaleCar : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ANormaleCar();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

protected:

	//UPROPERTY(VisibleAnywhere)
		//class USkeletalMeshComponent* SkeletalMesh;

	UPROPERTY(VisibleAnywhere)
		class UPoseableMeshComponent* PoseMesh;

	// Scale of the skeletal mesh
	UPROPERTY(VisibleAnywhere)
		float Scale = 3.0f;
};
// NormaleCar.cpp

```

// Fill out your copyright notice in the Description page of Project Settings.

#include “NormaleCar.h”

// Sets default values  
ANormaleCar::ANormaleCar()  
{  
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.  
PrimaryActorTick.bCanEverTick = true;

```
//SkeletalMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Sedan_SkelMesh"));
//static ConstructorHelpers::FObjectFinder<USkeletalMesh> ActorMesh(TEXT("/Game/VehicleVarietyPack/Skeletons/SK_NormalCar.SK_NormalCar"));
//SkeletalMesh->SetSkeletalMesh(ActorMesh.Object);

PoseMesh = CreateDefaultSubobject<UPoseableMeshComponent>(TEXT("PosebleMesh"));
static ConstructorHelpers::FObjectFinder<USkeletalMesh> ActorMesh(TEXT("/Game/VehicleVarietyPack/Skeletons/SK_NormalCar.SK_NormalCar"));
PoseMesh->SetupAttachment(RootComponent);
PoseMesh->SetSkeletalMesh(ActorMesh.Object);

//static ConstructorHelpers::FObjectFinder<UPoseableMeshComponent> PPMesh(TEXT("/Game/VehicleVarietyPack/Skeletons/SK_NormalCar.SK_NormalCar"));

// The bone's location
//Location(10.0, 0.0, 0.0);
//Rotation(2.0, 1.0, 3.0, 4.0);
//BoneName("Wheel_Front_Left");

```

}

// Called when the game starts or when spawned  
void ANormaleCar::BeginPlay()  
{  
Super::BeginPlay();

}

// Called every frame  
void ANormaleCar::Tick(float DeltaTime)  
{  
Super::Tick(DeltaTime);  
FVector Location(10.0, 10.0, 0.0);

```
//The bone's rotation
//FQuat Rotation1(0.0, 1.0, 1.0, 1.0);
FRotator Rotation(0.0, 0.0, 45.0);

FName WFL("Wheel_Front_Left");
FName WFR("Wheel_Front_Right");
//FTransform Transform(Rotation, Location, FVector(Scale));
PoseMesh->SetBoneRotationByName(WFL, Rotation, EBoneSpaces::ComponentSpace);
PoseMesh->SetBoneRotationByName(WFR, Rotation, EBoneSpaces::ComponentSpace);
//PoseMesh->SetBoneLocationByName(BoneName, Location, EBoneSpaces::ComponentSpace);
//PoseMesh->SetBoneTransformByName(BoneName, Transform, EBoneSpaces::ComponentSpace);
PoseMesh->SetWorldScale3D(FVector(Scale));

```

}

hope my code help someone  
thanks
