I have a GameMode
, a PlayerController
and a Pawn
class.
In the GameMode
constructor I spawn my pawn and store it a private array
AMainGameMode::AMainGameMode()
{
auto* spawnedPawn = GetWorld() ? GetWorld()->SpawnActor<ASecondPawn>() : nullptr;
if (spawnedPawn)
_SpawnedActors.Add(spawnedPawn);
}
In the pawn class constructor I make it autopossess Player0
ASecondPawn::ASecondPawn()
{
//...Other stuff...
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
In the PlayerController
I declare a private pawn member and try to possess the pawn linked to the Player0
void AMainPlayerController::BeginPlay()
{
Super::BeginPlay();
auto* spawnedPawn = GetWorld() ? UGameplayStatics::GetPlayerPawn(GetWorld(), 0) : nullptr;
if (spawnedPawn)
{
Possess(spawnedPawn);
AttachToPawn(spawnedPawn);
_PossesedPawn = spawnedPawn;
}
}
The pawn is spawned and inside the controller I can see my pawn but the AttachToPawn()
has no effect as the 2 actors are still separated in the world outliner.