Update PlayerName on PlayerState and let the other players see the change


I’m developing a multiplayer game for the first time. So, I have NO IDEA about how to do it.

I have a blueprint widget, which appears at the beginning of the game, where the player needs to set his/her name. When the player pressed the Enter key it runs:

By the way, I don’t know why it always appears an error in the Set Player Name node. I have to delete it a create it every time.

I have created a custom PlayerState class header:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerState.h"
#include "OpenDoorPlayerState.generated.h"

class MULTIPLAYERTEST_API AOpenDoorPlayerState : public APlayerState

	virtual void OnRep_PlayerName() override;

	virtual void SetPlayerName(const FString& S) override;

And the code:

#include "OpenDoorPlayerState.h"

void AOpenDoorPlayerState::OnRep_PlayerName()

	// Update The name in the widget on his head


void AOpenDoorPlayerState::SetPlayerName(const FString& S)

	ENetMode NetMode = GetNetMode();

	UE_LOG(LogTemp, Warning, TEXT("[ AOpenDoorPlayerState::SetPlayerName ] "));

Also, I have created a blueprint class that inherits from the above, BP_OpenDoorPlayerState.

But, when I run the above blueprint code, on the client, it doesn’t call the OnRep_PlayerName because the GetNetMode(); returns NM_Client.

How can I make run OnRep_PlayerName function?

I think the problem is that I don’t know how to run the blueprint code on the server.

a) if you are changing a value relying on an OnRep_ function and you want the function to be run on the server then you have to call it manually on the server (it should run automatically on client but server version needs to be called by hand).

b) Is this a dedicated server? If so blueprints are not spawned on dedicated servers (there is only gameplay logic and no “presentation” logic there by default).



No. I’m testing it this way because this is the first time I work with multiplayer.


void AOpenDoorPlayerState::SetPlayerName(const FString& S)

	ENetMode NetMode = GetNetMode();

	// check if this is on server
	if (HasAuthority()) {
// if server vall on_rep manually because server will not call it

	UE_LOG(LogTemp, Warning, TEXT("[ AOpenDoorPlayerState::SetPlayerName ] "));

in the specific case of a listen server you could probably do a comparison

if(NetMode == ENetMode::NM_ListenServer){


I think it should work but, I don’t think this is a standard way to do it.

I don’t think it doesn’t have so difficult to update the PlayerName in the PlayerState on the server.

Thanks again.

Answered in the other thread the OP created.