1.3 - Variable Replication

1_3.png

In order to view both Server and Client perspectives, on the Play dropdown, set the Number of Clients field to 2.

Variables that are important to gameplay should ONLY be modified on the Network Authority (Server), and then replicated to Remote Machines (Clients) on a need-to-know basis.

In this example, the ghost's health is being modified on a timer exclusively on the Network Authority. In the non-replicated ghost, the remote machines never receive updated health values. In the replicated ghost, they receive updates as the Server changes the health.

Blueprint Breakdown

In the BP_Ghost_Variable_Replication_None Blueprint's Event Graph (pictured below), you will see that the script calls for both Initialize Health and Update Health (which is called via a timer every 3 seconds) to only occur on the Server.

Click for full view

Also, each tick the text of the ghost's health is displayed to verify the value of the variable. For this Blueprint however, the variable for Health is not set to replicate so the value will always remain the same.

In the BP_Ghost_Variable_Replication_Enabled Event Graph (pictured below), you will see the same setup as above, however the Health variable is set to replicate.

Click for full view

Allowing Replication on the variable for Health can be done by enabling the checkbox in the Details panel of the variable as seen below.

1_3_Rep_Variables.png

With the variable set to replicate, this Blueprint will recieve updates to the variable that are performed by the Server as seen in the gameplay example below.