I have a player controller subclass (in C++) which my game mode it set to use by default.
From the editor, I wish to add a few pawn subclasses (also written in C++) into the scene, and assign these pawns to their own player controllers. What I’ve done is, in my player controller class, I’ve added a UPROPERTY variable which accepts a pointer to one of my pawn subclasses, effectively allowing me to use a drop-down list box to choose the corresponding pawns sitting in my scene…
The problem is, once I choose a pawn in my scene, nothing happens. The drop-down list still says “None”, and the reference is never assigned. If I drag the pawn from the World Outliner into the player controller drop-down list box, it gets a green highlight, indicating that it is compatible. But even a drag-and-drop operation doesn’t actually assign the reference!
Here’s the code from my player controller:
TPPlayerController.h
:
UCLASS(Blueprintable)
class TAOOFPEG_API ATPPlayerController : public APlayerController
{
GENERATED_BODY()
public:
virtual void SetupInputComponent() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, DisplayName = "Card Hand", Category = "Game Properties")
ACardHandPawn *CardHand;
};
TPPlayerController.cpp
:
void ATPPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
EnableInput(this);
if (!IsValid(CardHand)) {
auto loc = FVector(-800.0f, 60.0f, 900.0f);
auto rot = FRotator::MakeFromEuler(FVector(0.0f, 60.0f, 0.0f));
CardHand = GWorld->SpawnActor<ACardHandPawn>(ACardHandPawn::StaticClass(), loc, rot);
CardHand->EnableInput(this);
InputComponent->BindAction("DrawCard", EInputEvent::IE_Pressed, CardHand, &ACardHandPawn::DrawCard);
}
}
You might notice that I am explicitly spawning a pawn into the scene. This is just a temporary solution, for debugging purposes. What I really want to do is place these pawns in the scene with a given transform (in the editor, NOT in code), then have individual player controllers assigned to each of them. How can I do this?