Online Multiplayer - jgoffeney/Cesium4Unreal GitHub Wiki

Back

Description

Notes on how to implement online multiplayer.

References

Replication

Terminology

  • Replication: sending one players actions and events to the others
  • Dedicated Server: an application instance that solely acts as a host.
  • Listener Server: an application instance that acts as both a server host and a player client

Initial Example

  • Create a new project with the Third Person template.
  • By default it has a player start so to test the multiplayer add another PlayerStart actor and call it NetworkPlayerStart.
  • To do network testing within the editor go to the play option (for UE5 the 3 vertical dots next to the play controls for the viewport).
    • Increase the Number Of Players to 2.
    • Under Net Mode set it to Play As Listen Server.
    • Then select new Editor Window (PIE) which will immediately launch new windows for each player view.

SetEditorPlayers

Player Replication

Within the ThirdPartyCharacter is a Replication section with all the parameters for replicating player movement between clients.

ThirdPartyReplication

A few parameters (UE5) that by default are set:

  • Replicate Movement: check to replicate movement across clients via a multicast.
  • Net Load on Client: the actor is loaded on the clients during map loading.
  • Replicates: the master checkbox to enable/disable replication for the ThirdParryCharacter.

Events

Games are event driven where an event is a cause which runs a function for the effect. Below is a sample event added to ThirdPartyCharacter that causes the player to run while the left shift key is depressed.

RunEvent

When playing from the host instance both players will see the server player speed up and slow down. But when playing as the client player the run event is not fired on the server. But on the client the movement stutters because the client is running but the server is forcing its location in the non-running state.

The problem is input events (like key presses) are local events and do not replicate. But custom events have a replication property so can just create custom events that do the same thing as the input event but have the key press event then fire the custom events with replication (Run on Server) enabled.

CustomEvents

However it is now possible that the client will still stutter because the events are being executed on the server and then pushed back to the client. By having both the original and custom graphs the events will fire on both server and clients.

CustomEvents2

Relevancy

Relevancy is the measure of important to optimize network traffic. Not every client needs to be aware of every operation in the game.

There are three built in levels of relevancy under the Replication section:

  • Always Relevant : the server will replicate the actor for all the clients
    • Important for things that globally affect a game, such as, the position of a ball in a sports game.
  • Only Relevant to Owner :
    • Only the owner of the event gets the update. In the video example only the client that opens the door (client 1) with this setting will see the door open.
    • But if client 2 opens the door, the door itself will be unloaded from client 1 as it loses ownership (but the server still has the door and prevents client 1 from moving through the apparently empty space).
  • Net Use Owner Relevancy : only players within a given distance need to get the update so in the door example all clients near the door will get the replication of the door.
    • Net Cull Distance : the distance setting for the radius of relevancy