Replicating Display Name On Character

Hello all,

I have a widget that is a component in my character blueprint that contains a display name text component, and a health bar component.
The players connect to a dedicated server session, and the problem is that I am unable to get the player that just joined the session to have the name and health automatically placed on the already in game players. But all the already in game players can see the new player’s name and health (player name is already saved in the player state before joining the session).

These will be noobie questions, but here I go:
1- In the “Event OnPostLogin” in Game Mode, what is the best practice to display the names of all players that are already in the session? (Player name and health are saved in the player state)
2- Is it bad to multicast to all clients when a player joins, and loop every actor of type character and set the display name and health bar based on the variables in the player state?

Any help is most appreciated

Thanks in advance!

Are you using variable replication to replicate the display name?

The examples in the documentation are actually pretty good, i suggest you take a look at these - not much to read, but clear and short description with a few very basic examples.

Hey there Fronzelneekburm, Thank you for ur reply.

As i have mentioned i am using player state to save the player name and health, and the player state is replicated by its nature.
And i have taken a look at the documentation and i see a difference where the text is being set in the event tick, while what i am doing is setting only once when the player joins the session. Maybe that’s my problem, but isn’t it too much to put it in the event tick when it only needs to be set once or only updated when needed?

  1. No, it’s not terribly bad to multicast to all players when a new player joins.

However, the easiest way to do this might be to put the data on the player Actor (Pawn.)
Make the Pawn contain the hitpoints and name, and add itself to the local “all players display” widget when it’s instantiated in the level.
As long as all player Pawns are properly always relevant, this means that each client will always know of the name and hitpoints of each player.

But, the “proper” way to do this is to use PlayerState, and get to the PlayerState from the GameState, on each client.
As long as the states and variables are replicated and marked always relevant, you shouldn’t have to do anything more than set the values once (plus when they change.)
This is assuming that your GUI knows how to update the values when they change, of course. (OnRep may be the easiest way to get that)

Thank u for the guidance jwatte!

Well i guess i’ll stick to number 2 since it is working for me, and my GUI is working with repNotify.

Ijust wanted to check if it was a proper way to do it.

I remember there used to be a bug that on BeginPlay you can’t get PlayerState on the same frame. Did you try a small delay?

I actually did, i thought it was something related to a small time needed in order for the player state to be replicated on all clients. Didn’t know it was a bug :stuck_out_tongue:

Thanks for mentioning it!

I’ve only been able to display one players name from the player state, i tried casting from my game mode to get all the player controllers, but the cast seems to be failing… any ideas?