For clarity…
On Join the Game Mode
creates a controller and replicates it to the joiner. Server stores a copy.
It then Spawns the default pawn
and possesses it with said controller. The pawn itself being set to replicate, will eventually replicate to the owner and all others.
Copies of controllers are not replicated to other players. Only the owning client and the server have copies of controllers.
Players States for all players are stored in the Game State PlayerStates
array. The owning controller has a reference to its “owned” player state.
The GameState
and its PlayerStates
array is replicated to all clients.
For sanity sake you can use OnPostLogin in the GM to store a copy of all controllers for your usage. e.g. PlayerController array. Just be sure to CAST to your specific controller class before storing.
Replication only works if the Server makes the change. It’s always Server → Client.
RepNotifies are used for function processing upon variable state change. Thus the OnRep_function that’s automatically created. These are great for state persistence. Say a door state in which the onrep function controls the opening/closing action based on the variables value.
Remote Procedure Calls (RPC) are used to “Request” an action or “Notify” the server of an action.
e.g. Input Fire of a weapon.
You’d RPC the server notifying it you pressed Fire. It in turn validates if you can fire (has weapon, weapon has ammo etc). If Valid it spawns an authoritative projectile.
In a sense its a notification and a request. “Hey I did this, can you spawn a projectile?”
Multicast is a Server → Client response that is sent to all clients. MC’s target an event in the class it was called from on the server.
e.g. A MC executed in the character class on the server will call the character class on the clients.
If you need to execute logic on all client controllers there’s two approaches that are definitive.
- Loop the GM playercontroller array and call an event on each.
- MC from character class (on server) to call an event that calls a player controller event.
Do not forget to filter your called multicast events. Use Get Local Role to specify which proxy is allowed to execute the logic.
e.g.