Multiplayer flow a five year old could understand

I need someone to explain some basic multiplayer flow tips and tricks to me for a better understanding.

I have so many questions, but have a hard time fully understanding so if you respond, can you respond with a screenshot of what you’re describing and explain like I’m a child (as weird as that sounds haha) I’m trying to make a cheat sheet with all this information on it so I can study and apply. I’m a visual learner and reading causes me more confusion than a simple image can.

Please focus on the “Do this” not the “Don’t do this”.

Things I’m struggling with

  • How do I get a player controller reference in the Player Character, Game Mode or elsewhere?
  • How do I specify which player controller I want to communicate with?
  • When do I specifically need to make a RPC to the server?
  • What techniques do you guys use to pass information from a player state or game state to a widget?
  • How does Replication on a skeletal mesh work?
  • How can I load a save from a Game Instance for the specific player controller/player
  • In what cases do I specifically use SwitchHasAuthority

I appreciate any wisdom you have to share!

1 Like

It general depends on the context/scenario of the code.

Player Character referencing controller should be done on begin play, preferably a polling process.

What you’ll normally see is Begin play → delay etc. Delays in Begin play are dirty hacks.

Polling approach…

image


GameMode only exists on the server. So the only reference that should ever exist for it should be in the server-side controller.

Event on Posses (controller) or directly set it in the game mode via Event On Post Login


If you are trying to pass ID’s etc for a reference to a Pawn or Controller your design is wrong. Any logic that requires referencing another player needs to be run on the server-side.

RPC the server to execute an event to trace hit the target Pawn, then get a reference to its controller, then process the specific logic. This process varies depending on scenario and executing codes purpose.

Anytime you want the server or the servers authoritative proxy to do anything.
Never pass values to the server to explicitly use. e.g. mouse pitch/yaw
The server must determine its on values to maintain authority.

Again, When depends on the “thing” you are trying to do.

PS/GS would call specific events on the Owning Controller and pass the values. The event would execute logic to update the Widget.

Skeletal Meshes, Static Meshes do not replicate.

Jump to the Debugging, Profiling, and Testing section, then scroll up 2 paragraphs. Read thoroughly.

@Everynone can answer this one.

It varies, Look at the macro code.

Better to understand Actor Local and Remote Roles

3 Likes