How can I Change The Name in PlayerState BP?

Actually I want to change the name of the Player Name (of PlayerState BP), is it there any way to do this,??? from where can i change this???

/** Player name, or blank if none. */
UPROPERTY(replicatedUsing=OnRep_PlayerName, BlueprintReadOnly, Category=PlayerState)
FString PlayerName;

Unreal has set this variable to BlueprintReadOnly, meaning you cannot change the value of PlayerName from a blueprint, only read it. To change it you need to do it in a C++ PlayerState Class.

but its working in this way too…
just set the Name in menu widget ,and store it to my gameInstance(GIBP)…

then when the game starts,it cast PlayerState BP(PS) and calls a function(Update Name) from it

this is my PlayerState BP

then it shows the name of the Player (from PS BP) on pressing ‘P’ button

but the problem is that , its only working for the player who is hosting the game,not working for other clients

@Blagy, any solution?

Nor the variable of the player state itself nor its setter are exposed to blueprints I am afraid:

/** set the player name to S */
	virtual void SetPlayerName(const FString& S);

If you want to use a custom variable then you need to set it to replicated. This way it will work for all clients differently.

Actually i want to set my Players name in PlayerState BP( like his Name/text) , then want to cast the PlayerState BP extract the name and show both of their name by using a Print Node whenever any Player causes a Damage to other Player. Is there any way to do that, if so then can you please show me an example BP of that

@Balgy, please

You can use the node “Execute Console Command” with the command SetName Tim to change the name to Tim. The Specific Player parameter is the PlayerController of the player you want to change the name of. Clients only have their own PlayerController and therefore can only change their own name.

The initial name should be set during the OpenLevel node on the client with the Option ?Name=Tim, otherwise the name variable will be set to default until the variable has been replicated.

1 Like

On which reason Player name is only C++ accessible?
I see no reason. Is it not a very simple variable?
Would be nice to see it accessible on BP. I see no reason to switch to C++ just to assign player names in player state. :frowning:

1 Like

You can create a custom player state, add a string for name, set it as replicated, then create BP node “updateName” with string input that runs on server within that player state that set the name when called. So a player controller (client) would call event “requestUpdateName” on player controller (server) passing a name you set maybe in the client’s game instance. Player controller (server) would get state from self (server version) and call the updateName event. Then you have to wait for the GameState & PlayerState to replicate that String back down to the client. This happens automatically but takes time. It may be None or invalid at first on the client side until it has time to replicate down. All vars must be changed on the server.

Or can use the Advanced Sessions Plugin.

312880-ps.png

1 Like

Golly i was struggling forever in UE5.1. I’m new to player states and was so confused. I thought I didn’t need to make this call since the custom variable i made had “replicated” in the client’s playerstate. The mind set was playerstates just auto sync up, i guess not, you need to push/update it to the “server playerstate” then it gets replicated.

hey i made a quick youtube tutorial here about this…there is actually a built in function in the game mode to allow you to do this!