Looping through Player Array then casting to custom player state only returns local player state variables?

Hey all,

I’ve been trying to figure out a way to get an in world multiplayer scoreboard working. After several days of failing, I’ve boiled it down (I think) to this issue:

Getting the player array from the game state, then casting to your custom player state, does not return the client’s variables. It returns the local player state variables.

Here’s my test event (this is in my Game State):

The above BP will print twice (as it’s a 2 player game, and the player array correctly shows 2 connected players). If I add a debug print for each array element, it correctly shows 2 different player states.If I add a debug print after the cast to my custom player state, it shows the 2 unique custom player states. But the variables it returns are only from the local custom player state.

The end result is both prints will be the local variables (player name and current lives). Note that Struct_PlayerData and LivesCurrent are both replicated, and I have a delay earlier in the execution chain to ensure that the player states have all loaded before this event is run.

The issue seems to be with the cast to my custom BP_PlayerState. After that cast, the event is only looking for my local BP_PlayerState, and I have no idea how to fix it as I have to cast to retrieve the variables.

Any ideas?

1 Like

I so rarely get any answers on this website - so I’ll just answer this myself in case anyone else searches.

My partner (the engineer) looked at this and figured it out. The problem has to do with server authority. The server did not recognize the client’s player state variables as changed, because that change occurred locally (through loading a save game). When the server then goes looking for the player state variable, it does not recognize the new data.


  1. Have the server get the client’s desired name from a variable on the player state, and set the actual player name to that data. “Oh, the client wants to be called Bobby? I agree, let’s call him Bobby”. The server then changes the name to exactly what the client thinks it should be, and now it correctly reads the variable as the client intended.

One way to achieve this is to have an event that runs on server, with a parameter of the variable you want to change (in my case above, STRUCT_PlayerData). The server will then grab that parameter and change it to whatever you want - and as it has authority, the change is recognized and can be used by the server when requested by other clients.

Another solution is to have a smart engineer with you at all times.

1 Like