Hello!
Im trying to create a multiplayer game, I have the Spawn logic in the GameMode, so the server spawns the Player Actor and then the controller possess it.
The problem is that I have the logic of creating the widget and adding to the viewport in the Pawn, because I want to switch pawns while gameplay.
So, when the GameMode does the part ThisController->Possess(Pawn), this goes to the PossessedBy and there I trigget a Client RPC to create the UI.
But GetOwningPlayerPawn() in the UI Widget returns null.
To be more clear, if I do this:
void UCMainCharacterWidget::NativeOnInitialized()
{
Super::NativeOnInitialized();
if (!GetOwningPlayer<ACMyPlayerController>())
{
UE_LOG(LogTemp, Error, TEXT("Get Owning Player not found"));
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("Get Owning Player not found"), true, true, FLinearColor(0.66,0,0), 10);
if (!GetOwningPlayer()->GetPawn<ACMyCharacter>())
{
UE_LOG(LogTemp, Error, TEXT("Get Owning Pawn not found"));
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("Get Owning Pawn not found"), true, true, FLinearColor(0.66,0,0), 10);
}
}
if (ACMyPlayerController* MyPlayerController = GetOwningPlayer<ACMyPlayerController>())
{
UE_LOG(LogTemp, Error, TEXT("BREAKPOINT 2"));
if (ACMyCharacter* MyPlayerCharacter = MyPlayerController->GetPawn<ACMyCharacter>())
{
UE_LOG(LogTemp, Error, TEXT("BREAKPOINT 3"));
MyPlayerCharacter->CPPlayerStats->OnStatChanged.AddDynamic(this, &UCMainCharacterWidget::UpdateHealth);
}
}
}
I dont get the “Get Owning XXXX not found”, so It has a correct ACMyPlayerController and ACMyCharacter.
I Get “BREAKPOINT 2” but not “BREAKPOINT3”.