I'm actually trying to make a lobby system in C++ with Unreal, but actually I'm facing a huge problem.
My widget is updated with replication when a player hits the ready button that toggles if the widget displays ready or not. It works perfectly on clients but the widget still remains unchanged on the listen server.
void ALobbyGamemMode::UpdatePlayerInfo(APlayerController* RequstingPlayerController)
{
if (!RequstingPlayerController) return;
ALobbyPlayerController* LPC = Cast<ALobbyPlayerController>(RequstingPlayerController);
if (!LPC) return;
// Find the slot for the requesting player
for (auto PS : PlayerSlots)
{
if (PS && PS->GetPC() == RequstingPlayerController)
{
// Create the updated player info
FPLayerInfo NewInfo;
if (RequstingPlayerController->PlayerState)
{
NewInfo = FPLayerInfo(RequstingPlayerController,
FText::FromString(RequstingPlayerController->PlayerState->GetPlayerName()),
LPC->GetPlayerInfo().bIsReady,
RequstingPlayerController->PlayerState);
}
LPC->PlayerInfo = NewInfo;
LPC->ForceNetUpdate();
LPC->OnRep_PlayerInfo();
// Update THIS player's character widget
if (PS->GetSelectedCharacter())
{
PS->GetSelectedCharacter()->UpdatePlayerInfo(NewInfo);
UE_LOG(LogTemp, Warning, TEXT("Updated character info for %s - Ready: %s"),
*RequstingPlayerController->GetName(),
NewInfo.bIsReady ? TEXT("Ready") : TEXT("Not Ready"));
}
// BROADCAST: Send this player's info to ALL OTHER PLAYERS
for (auto OtherPC : Controllers)
{
if (OtherPC)
{
ALobbyPlayerController* OtherLPC = Cast<ALobbyPlayerController>(OtherPC);
if (OtherLPC)
{
OtherLPC->Client_UpdateCharacterWidget(NewInfo);
}
}
}
if (ALobbyPlayerController* ServerLPC = Cast<ALobbyPlayerController>(RequstingPlayerController))
{
if (ServerLPC->IsLocalController()) // This is the server’s own controller
{
APawn* Pawn = ServerLPC->GetPawn();
if (Pawn)
{
if (AThirdPersonneCharacter* CharPawn = Cast<AThirdPersonneCharacter>(LPC->GetPawn()))
{
CharPawn->SetPlayerInfo(NewInfo);
};
}
}
}
CheckAllPlayersReady();
break;
}
}
}
void AThirdPersonneCharacter::OnRep_PlayerInfo()
{
if (!PlayerInfoWidgetComponent)
{
UE_LOG(LogTemp, Error, TEXT("PlayerInfoWidgetComponent is NULL on %s"), *GetName());
return;
}
UUserWidget* Widget = PlayerInfoWidgetComponent->GetUserWidgetObject();
UPlayerInfoWidget* InfoWidget = Cast<UPlayerInfoWidget>(Widget);
if (InfoWidget)
{
InfoWidget->UpdatePlayerInfo(PlayerInfo);
PlayerInfoWidgetComponent->SetVisibility(true);
UE_LOG(LogTemp, Log, TEXT("Updated PlayerInfo on %s"), *GetName());
}
else
{
UE_LOG(LogTemp, Warning, TEXT("OnRep_PlayerInfo: Widget not yet created for %s"), *GetName());
}
}
lang-cpp
PlayerSlots? Are you sure you not making a copy of the elements and modify those? I think you meanauto&in thefor(auto PS: PlayerSlot)andfor(auto OtherPC: Controllers)