0

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());
 }
 
}
asked Sep 15 at 12:28
1
  • What is the type of PlayerSlots? Are you sure you not making a copy of the elements and modify those? I think you mean auto& in the for(auto PS: PlayerSlot) and for(auto OtherPC: Controllers) Commented Sep 15 at 13:07

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.