Hi!
I’ve just started to develop my first Multiplayer game. There’ll be two players with their names above of their heads. I’m using a Blueprint Widget to show it.
When the game begins, the player has to set his/her name. I have a Blueprint widget with an Editable Text. This is how I show this blueprint widget:
When the player hits the Enter key in the Editable Text:
I have created my custom PlayerState in C++.
The header:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerState.h"
#include "OpenDoorPlayerState.generated.h"
/**
*
*/
UCLASS()
class MULTIPLAYERTEST_API AOpenDoorPlayerState : public APlayerState
{
GENERATED_BODY()
protected:
virtual void OnRep_PlayerName() override;
UFUNCTION(BlueprintCallable)
virtual void SetPlayerName(const FString& S) override;
};
The code:
#include "OpenDoorPlayerState.h"
#include "Kismet/GameplayStatics.h"
#include "MultiplayerCharacter.h"
void AOpenDoorPlayerState::OnRep_PlayerName()
{
Super::OnRep_PlayerName();
AMultiplayerCharacter* PlayerCharacter =
Cast<AMultiplayerCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0));
if (PlayerCharacter)
{
UE_LOG(LogTemp, Warning, TEXT("[ AOpenDoorPlayerState::OnRep_PlayerName] Player Character Name: %s - PlayerName: %s"), *PlayerCharacter->GetName(), *GetPlayerName());
PlayerCharacter->ShowPlayersName(GetPlayerName());
}
}
void AOpenDoorPlayerState::SetPlayerName(const FString& S)
{
Super::SetPlayerName(S);
ENetMode NetMode = GetNetMode();
UE_LOG(LogTemp, Warning, TEXT("[ AOpenDoorPlayerState::SetPlayerName ] %s"), *S);
}
The ShowPlayersName
is:
UFUNCTION(BlueprintImplementableEvent)
void ShowPlayersName(const FString& PlayerName);
In blueprints:
The problem is: if updates the blueprint widget in the client, but the player running as a listen server it doesn’t. If I change it in the listen server, the client doesn’t see the updated name.
When the game starts:
Output log:
LogNet: Join request: /Game/MultiplayerTest/Maps/T_BlockoutMap?Name=Melnibone-20B6B133447A6510DA00D09D26FD93A7?SplitscreenCount=1
LogOnlineSession: Warning: OSS: No game present to join for session (GameSession)
LogTemp: Warning: [ AOpenDoorPlayerState::OnRep_PlayerName] Player Character Name: BP_MultiplayerCharacter_C_0 - PlayerName: Melnibone-20B6B13344
LogTemp: Warning: [ AOpenDoorPlayerState::SetPlayerName ] Melnibone-20B6B13344
LogNet: Join succeeded: Melnibone-20B6B13344
LogOnlineSession: Warning: OSS: No game present to join for session (GameSession)
LogTemp: Warning: [ AOpenDoorPlayerState::OnRep_PlayerName] Player Character Name: BP_MultiplayerCharacter_C_0 - PlayerName: Melnibone-7894D3E242
LogOnlineSession: Warning: OSS: No game present to join for session (GameSession)
LogTemp: Warning: [ AOpenDoorPlayerState::OnRep_PlayerName] Player Character Name: BP_MultiplayerCharacter_C_0 - PlayerName: Melnibone-20B6B13344
After setting the name on the listen server:
Output log:>
LogTemp: Warning: [ AOpenDoorPlayerState::OnRep_PlayerName] Player Character Name: BP_MultiplayerCharacter_C_0 - PlayerName: NameListenServer
LogTemp: Warning: [ AOpenDoorPlayerState::SetPlayerName ] NameListenServer
LogTemp: Warning: [ AOpenDoorPlayerState::OnRep_PlayerName] Player Character Name: BP_MultiplayerCharacter_C_0 - PlayerName: NameListenServer
After setting the name on the client:
Output log:
LogTemp: Warning: [ AOpenDoorPlayerState::OnRep_PlayerName] Player Character Name: BP_MultiplayerCharacter_C_0 - PlayerName: NameClient
LogTemp: Warning: [ AOpenDoorPlayerState::SetPlayerName ] NameClient
LogTemp: Warning: [ AOpenDoorPlayerState::OnRep_PlayerName] Player Character Name: BP_MultiplayerCharacter_C_0 - PlayerName: NameClient
Do you know what it is happening?
Thanks!