Set property on a custom player controller


I have my custom player controller class, e.g. “MyPlayerController” in which I have the following property:

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Rotation Target")
class USceneComponent* RotationTargetComponent;

I wanted to use it in UpdateRotation to make the PC always look on a specific scene component.

  • How can I in editor set this property to be some other actor from the scene?

(I don’t know how to do it since the player controller spawns only when I hit “play”)

Or maybe there is a better way to make my camera look at a specific actor?

Ok, did it (this post about Blueprints context was very helpful in finding proper nodes - Blueprint Editor Tips and Tricks - Unreal Engine).

This is how I did it:

(My PlayerController’s class is Planet2PlayerController, and the object I want to look at is named PlanetBody1)
And in the code of my player controller I have:

void APlanet2PlayerController::UpdateRotation(float DeltaTime)
    FVector targetPosition;
    if(RotationTargetComponent != nullptr)
        targetPosition = RotationTargetComponent->GetComponentLocation();
    APawn* const P = GetPawnOrSpectator();
	if (P)
        FVector thisLocation = P->GetActorLocation();
        FVector diff = targetPosition - thisLocation;

Phew! Beginnings are hard and I hope it helps someone one day.