I made a CustomGameState (parent class GameState, CustomGameMode is also a child of GameMode not Base), and inside it I created a variable “String Test” and set it to Replicated. Then inside the CustomGameState I made a custom event “UpdateTest” in which I’m setting the “Test” value to a new one from the input of the custom event.
Then I tried each of the Replicates of the custom event to see the effect, but neither of them, when it was called from client, updated the value for all other clients as well as the host.
Here are the results: Multicast:
Host call: Host updated | Clients updated
Client call: Host not updated | Other clients not updated | Local GameState updated
Run on Server:
Host call: Host updated | Clients updated
Client call: Host not updated | Other clients not updated | Local GameState not updated
Run on owning Client:
Host call: Host updated | Clients updated
Client call: Host not updated | Other clients not updated | Local GameState updated
“UpdateTest” is called from a widget’s button, and on each tick the “Test” value is used in SetText for a Text inside the widget.
What am I doing/understanding wrong? Shouldn’t GameState be accessible and modified by everyone, not just the host? I know that the GameMode is only available on host.
Client->Server calls only work if the calling client owns the actor.
In general they’ll only work on PlayerController, Character, or PlayerState.
Move your call to either of these classes, then access GameState from the server side there and modify your variable. Once the variable is modified on server side it will be replicated to all clients.
This does work (added in Player Controller for this test), but is this how you are suppose to do it from performance perspective (network and components usage)? Here it was only a String as a test, but when I’m getting into real levels, I see a lot of variables that need to be changed (from GameState as well as PlayerState) and some quite frequent.
Or there really isn’t a more effective/less costly way to do it?
Some calculations I guess you would do them on client side first and only send the “result” to the host to change the variable, and not the parameters/inputs and let the host do all the calculation and then change the variable.
Dunno what kind of game you doing but in general the server should never trust the client.
If you can send parameters/inputs to the server and let the server do the calculations it’s generally better.
In some cases you may want to to the calculations on the client to get an immediate visible result (no lag) on the client, then you send to the server and server does the calculations again for validation and replication to other clients.
Keep in mind that every frame (60 times per second), you client sends its position, rotation, and acceleration vector to the server. And server calculates player movement from that, and replicates to everyone. In comparison, changing a few variables here and there on the game state or player state shouldn’t have much impact.