Set rotation of Actor using FRotator in C++

I am trying to set the transform values for an Actor using C++. Here is the code:

double rand_posX = 10;
double rand_posY = 10;
double rand_posZ = 10;
double rand_pitch = 45;
double rand_yaw = 45;
double rand_roll = 45;
FTransform ReturnTransform;
ReturnTransform.SetLocation(FVector(rand_posX, rand_posY, rand_posZ));
ReturnTransform.SetRotation(FRotator(rand_pitch, rand_yaw, rand_roll));
return ReturnTransform;

I get an error at the FRotator line which says: no suitable user-defined conversion from “FRotator” to “const UE::Math::TQuat” exists

Please help me fix this error and if there is a more elegant way to set the transform of my actor, I would appreciate it. Thank you!

Hi xianthryllis,

The “SetRotation” accepts a Matrix rather than a FRotator.

The simplest thing you can do is to just re-write the bit that sets the Transform values to set them in it’s constructor:

FTransform ReturnTransform(FRotator(rand_pitch,rand_yaw,rand_roll),FVector(rand_posX,rand_PosY,rand_posZ),FVector(1,1,1));
1 Like

Thank you very much!!

1 Like