How to do it...

  1. From the Modes tab, under the Place section and under Basic, drag and drop a Cube object into your scene.
  2. From the Details tab, go to the Transform component and change the Mobility property to Movable.
  3. Afterwards, click on the Add Component button and select New C++ Component.
  4. From the menu that pops up, select Actor Component and select Next:

  1. From there, give your component a name, for example, RotateActorComponent, and then press the Create Class button.
  2. Construct your FRotatorFRotators can be constructed using a stock pitch, yaw, and roll constructor, as shown in the following example:
FRotator( float InPitch, float InYaw, float InRoll ); 
  1. Your FRotator will be constructed as follows:
FRotator rotator( 0, GetWorld()->TimeSeconds, 0 ); 
  1. The standard orientation for an object in UE4 is with Forward facing down the +X-axis. Right is the +Y-axis, and Up is +Z.
  2. Pitch is rotation about the Y-axis (across), yaw is rotation about the Z-axis (up), and roll is rotation about the X-axis. This is best understood in the following three points:
You should note that in other conventions, the X-axis is pitch, the Y-axis is yaw, and the Z-axis is roll.
  1. Apply your FRotator to your actor using the SetActorRotation member function, as follows:
// Called every frame
void URotateActorComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

FRotator rotator(0, GetWorld()->TimeSeconds, 0);
GetOwner()->SetActorRotation(rotator);
}