Download

how to replicate from client to server in blueprints

Hello everyone. I cannot replicate from client to server with blueprints.

I want to know how can I change a variable from client that will change on both server and client.

There is a string variable called “testStr” in myGameState. It’s default value is “default”.
When, the player press “H”, testStr from myGameState changed to “changed”.
When, the player press “J”, it prints the value of testStr.

So the client changes the testStr by pressing “H”, and shows the value “changed” when he press “J”.
But when the server press “J”, it shows the default value “default”.

I ticked the “replicate” property of myGameInstance in class defaults panel. I ticked the “replicate” property in variable testStr.

It seems like both the client and server has separate gameState and the client just shows it’s gameState and server just shows it’s gameState.
I have also tried with gameInstance too. Not working. Just showing the separate values of the variable.
I have also tried with gameMode. Client can’t cast to gameMode so it doesn’t work.

I have also tried changing the variable with a function with “run on server”, “multicast”, “run on owning client” in myGameState but they all fail and the server just shows the default value “default”.

Pls tell me how to change a variable by client that will change on both client and server. Thanks.

Just some quick points, the variable will need to be changed on the server for it to be replicated to the clients. If you would like the client to change the variable, then the easiest way would be to call a custom event which is run on the server.

You mentioned…

I ticked the “replicate” property of myGameInstance in class defaults panel. I ticked the “replicate” property in variable testStr.

Do you have this variable in both myGameInstance AND the Game State? The game state exists on both server and clients (replicated), the game instance however I believe is not replicated amongst server/clients.

If you have teststr set to replicated AND you are calling the change through a custom event in your game state which is run on the server, then it should work.

If you can post some pics of your setup it will be a lot easier to help narrow down a cause/fix :slight_smile:

Thank you very much for the reply. I tried with RunOnServer events but it seems like those RunOnServer events don’t trigger at all when called from client.pic1.jpg
pic2.jpg
3bfb07bd4a8b6e1377430b8321675f1e571b9bdf.jpeg
c30fdb421f6fc055f632bbe6aeb4260ee10121c2.jpeg

Ok, so I threw together your setup and tried to see if I could pin point where the issue was occurring. I was able to get it working with the following setup which looks to be the same:

8bedd17c4f174d896f850435ce30afb820484ef0.jpeg

My thought overall is that your setup looks correct so there might be an external influence which will be changing the result you are seeing. What I think it could be which may seem obvious, but make sure the correct game state is referenced in your game mode. Sometimes setting this in the project settings works, but others you might find that in the levels World settings that it might be referencing a different game mode, which also means a different game state.

Hope this helps!