Get components of actor and rotate them


I want to simulate some sort of roller conveyor. I started with one roll and it worked, I have an actor ( the roller ) which rotates infinitely.
Now I want one actor with multiple rollers, but if I copy my roller in the blueprint, and paste it beside the original one it just rotates around the original one.

I think I have to get all the components from the actor to rotate them simultaneously?

void ARotation::Tick( float DeltaTime )
	Super::Tick( DeltaTime );
    FRotator MyRot = GetActorRotation();
    MyRot.Roll += RotationRate * DeltaTime;

Thats the part where I can rotate one, but how would I do many?

You have a couple of options:

  1. Keep your actor the way it as (just rotating one roller) and place several instances of them in the level to get more.

  2. Put several rollers in one blueprint and change your code to the following (NOTE: Writing this off the top of my head so there might be small errors):

    TArray<UActorComponent*> comps;
    GetComponents( comps );
    for( int i=0; i < comps.Num(); ++i )
    UStaticMeshComponent* thisComp = Cast(comps[i]); //try to cast to static mesh component, assuming that’s what your rollers are
    if( thisComp )
    FRotator MyRot = thisComp->GetComponentRotation();
    MyRot.Roll += RotationRate * DeltaTime;

Thank you for your answer, your first suggestion would work, but it would be too much effort to get done what I want to do ( a roller conveyor ).
So I tried your second suggestion and it worked somehow, but not as expected, now all three rotate but they do not roll in place. All three of them rotate clockwise. Do you have any other suggestion?

I am really new in UE world and I really appreciate your help.

Thank you

If they’re not rolling it’s simply because they were placed in a different axis other than their own. Replace “MyRot.Roll” with “MyRot.Pitch” or “MyRot.Yaw” to see if one of those gets them rolling correctly.

‘Roll’ simply means, rotate around the ‘Z’ axis, assuming the object was made such that its ‘front’ faces the ‘Z’ axis. If it’s made any other way or placed in the BP in a different orientation, you can get a different result.