1.4 - Variable Replication [RepNotify]

An overview of the Network Features example level, example 1.4: Variable Replication (RepNotify).

Choose your operating system:





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

Oftentimes, it is desired to execute some logic in response to the value of a replicated variable changing. Variables that are marked RepNotify , have a special function called automatically any time the value is changed, on both Network Authority and Remote Machines.

In this example, the Network Authority controls changing a scalar value indicating which color the streetlight should display using a RepNotify variable. When the value is changed, the auto-generated OnRep function is called, which in this example then updates a material parameter.

Blueprint Breakdown

In the BP_Stoplight_Variable_RepNotify Blueprint's Event Graph (pictured below), you will see that the script calls for only the Network Authority to handle the light switching logic. The Streetlight Scalar variable representing the state of the light is specifically marked as RepNotify, so both the Client and Server have the OnRep_StreetlightScalar function called when the value changes.

Click for full view

The OnRep_StreetlightScalar function then handles updating the visuals of the streetlight such that it works on all machines.

Setting a variable to RepNotify can be done through the Details panel of the variable under the Replication drop down menu.


With this setup, both Client and Server see the same sequence executed for the streetlight when playing in game.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey