2.4 - Network Relevancy [Part 4 - Combination Solution]

Choose your OS:

2_4.png

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

Both examples 2.2 and 2.3 failed beacuase neither could handle the two cases the chest examples needs:

  • To play an instanteous effect at the time of interaction.

  • To preserve a change in state in the Actor over time.

Example 2.4 provides a hybrid solution by combining the use of the techniques used in 2.2 and 2.3 to effectively solve the problems. The Multicast function handles playing the instant gold effect for clients relevant at that specific time, while a replicated boolean preserves whether the chest lid is open or not. If the chest was not relevant for a client during the initial opening of the chest, the client will only see the lid open when the chest becomes relevant to them.

Blueprint Breakdown

In the BP_Relevancy_Replication_Combined Blueprint's Event Graph, as seen in the commented section below, the OnChestTouch is overriden to use a combination of a RepNotify variable and a Multicast replicated function.

2_4_Eventgraph.png

Properly displaying the chest has two components: one that is instantaneous (the gold particle) and one that is persistent state (the lid being open). The Multicast is employed to handle the instant event, while the RepNotify variable handles the persistent state.

Below is the OnRep function called when the variable bChestOpened is updated.

Click for full view

This example solves the issue we are presented and demonstrates proper usage of Multicast funtions and RepNotify variables. The result is what one would expect to occur when opening the chest in a networked game.