Replicating an object moving across all clients on a server


I have a widget blueprint with a button that is visible to one of the players randomly on a server. When this button is pressed its sets a variable in the my game state to true as shown below:

In the game state the event tick watches for the variable to becomes true, once its true it runs the event TrapDoors which effectively opens all of my trap door blueprint class components in the map as shown below:

At the moment it only works of the player which has the widget and presses the button is the server. In this scenario the movement of the door is replicated to all clients. However if the player which presses the button isn’t the server i.e. a client or run on a dedicated server then only that player sees the doors open. All other clients see the doors remain closed.

If tried setting the TrapDoors event to the various replicates options, the Trap Door Triggered variable is set to replicated. Obviously I am not understanding this properly.

Does anyone know what needs to be done to make the movement of the doors replicated to all clients on the server?

Replication only ever happens from the server to the clients so setting a replicated variable client-side results in nothing being replicated.

You need to ensure that you only SET the replicated variable server-side.

To move from client-side to server-side you need to call a RunOnServer event. This can however only be done on an Actor that the specific client “owns”. Since the server owns the GameState class and not your client you won’t be able to do a RunOnServer event from that. You can either use the PlayerController or the Pawn/Character the PlayerController controls or any Actors that the Pawn/Character owns.

Note that you also can’t use the UserWidget class to do RPC’s (remote procedure calls like RunOnServer, Multicast) since UserWidget’s only exist locally.