Gamestate replicates to clients, not server

Hi everyone !

I encounter some issues with variable replication using a dedicated server.

Some context : When a client launch my game, they have to log in so my external nodejs server can retrieve their ID stored in a postgresdatabase. This ID is then stored in a string called “User ID” that is saved in a game slot in order to retrieve it when the player connects to my dedicated server.

What I want now is to send my “User ID” of the last connected player to the server. I’m using a GameState to replicate the variable, using a “User ID GS” replicated variable.

This is my Pawn (BP_Pawn) blueprint, where I send the “User ID” to the replicated variable “User ID GS” in my gamestate everytime a client connects.

And this is my GameState (GS_VR) where I try to print my “User ID GS” variable. Both event are set on multicast.

So, my issue is that when I launch the game, every clients are able to retrieve the “User ID GS”, so this variable is replicated well. But I can’t manage to make the server retrieve it, what I don’t understand. The server print remains empty, and I can’t understand why.

To summarize, every clients can retrieve my “User ID GS” stored in a Gamestate, but my dedicated server can’t.

Oh, I didn’t know that clients aren’t able to alter the gamestate, thank you !

What kind of server-rpc can I use ? Only my clients know their own ID, so how can I manage to send strings to my dedicated server if I can’t use the gamestate to store data ?

Thank you again for your answer.

Thank you for your advice, I’ll try to set this up.

You’re right, it would be a shame if a client could alter the gamestate, so it makes sense. I didn’t think about cheaters x’).

As you said, clients are able to retrieve their userID in their own Pawn. Should I create a PlayerState and save it into, or can I keep storing it only in the Pawn ? Isn’t the Pawn also replicated to everyone ? I’ve never used PlayerState, I think I should read some docs about it.

The gamestate is server authoritive, that means you can’t alter it from the client. use a server-rpc to change it’s variables.

no problem. think about it - it is one of the most critical classes in multiplayer, so it would be really bad if a client can alter (cheat) the state for all the connected clients :wink:
what I recommend in your case, save the userID in the playerState (if the client retreives it). the player state is also replicated to everyone and can be pulled out of the gameState (playerArray). so you have a central place (also on the server) to collect all the ids.
for the rpc, just make a customEvent, set it to runOnServer, give it a inputParameter of type string, the call that event on your client and pass in the string variable you’d like.

if your clients dont change pawns while playing i guess it is also good in the pawn. just set the pawn to replicate, set the userID variable to also replicate and when you want to set the userID after login do it in a serverRPC like described above. and yes the pawn (if it is replicated) goes to all clients (beware of netculldistance!) so you can do somehting like getAllActorsOfClass(pawn) to get them and loop over them to retreive the userIDs.

I managed to make it works using Pawn. Thank you a lot for your help :).