Replication Example

Choose your OS:

To give a concrete example, consider the case where you are a client in a network game. You see two opponents running towards you, shooting at you, and you hear their shots. Since all of the game state is being maintained on the server rather than on your machine, why can you see and hear those things happening?

You can see the opponents because the server has recognized that the opponents are relevant to you (i.e. they are visible) and the server is currently replicating those Actors to you. Thus, you (the client) have a local copy of those two player Actors who are running after you. You can see that the opponents are running toward you because the server is replicating their Location and Velocity properties to you. Between Location updates from the server, your client simulates the movement of the opponents locally. You can hear their gunshots because the server is replicating the ClientHearSound function to you. The ClientHearSound function is called for a PlayerPawn whenever the server determines that the PlayerPawn hears a sound.

So, by this point, the low-level mechanisms by which Unreal multiplayer games operate should be clear. The server is updating the game state and making all of the big game decisions. The server is replicating some Actors to clients. The server is replicating some variables to clients. And, the server is replicating some function calls to clients.

It should also be clear that not all Actors need to be replicated. For example, if an Actor is halfway across the level and way out of your sight, you do not need to waste bandwidth sending updates about it. Also, all variables do not need to be updated. For example, the variables that the server uses to make AI decisions do not need to be sent to clients; the clients only need to know about their display variables, animation variables and physics variables. Also, most functions executed on the server should not be replicated. Only the function calls that result in the client seeing or hearing something need to be replicated. So, in all, the server contains a huge amount of data, and only a small fraction of it matters to the client - the ones which affect things the player sees, hears or feels.

Thus, the next logical question is, "How does Unreal Engine know what Actors, variables, and function calls need to be replicated?"

The answer is, whoever writes the code or sets up the Blueprint for a class is responsible for determining what variables and functions need to be replicated.