To ensure that the values are the same on both clients and servers, we use the process of replication. In this recipe, we will see just how easy it is to do so.
Replicating properties over the network
How to do it...
For this simple example, let's create a variable to store how many times each player jumps within the game:
- Open up Visual Studio and open the definition for your character for your project (in my case, it is Chapter_12Character.h). Add the following property and function declaration to the file:
UPROPERTY(Replicated, EditAnywhere)
uint32 JumpCount;
void Jump() override;
- Then, go to the implementation file and add the following #include:
#include "UnrealNetwork.h" // DOREPLIFETIME
- Afterwards...