Course contentsShow
← Unreal Engine Game Development
Lesson 45 of 8801. Foundations and Editor WorkflowFree lesson

Synchronizing Reflection Data Across Network Clients

Configure UPROPERTY replication settings to ensure that the reflection system correctly synchronizes object state between the server and connected clients.

Synchronizing Reflection Data Across Network Clients

In this lesson, you will learn how to use UPROPERTY specifiers to ensure that the variables tracked by Unreal’s reflection system are automatically synchronized from the server to your connected clients.

The Role of Reflection in Networking

As you know from our study of the reflection system, UPROPERTY macros allow Unreal to track and manage your variables. In a networked game, the server acts as the "source of truth." When you change a value on the server—like a player’s health or a door’s state—that information needs to travel across the internet to every client.

Unreal’s networking system taps into the reflection data you’ve already defined to identify which variables need to be sent over the wire. However, simply marking a variable with UPROPERTY() isn't enough; we must tell the engine how to handle that synchronization.

Configuring Replication

To enable synchronization, we use the Replicated specifier within our UPROPERTY macro. When a property is marked as Replicated, the reflection system registers it with the network replication engine.

Here is how you define a synchronized variable in your header file:

UPROPERTY(Replicated)
float CurrentHealth;

The "How" Behind the Sync

By marking the variable as Replicated, you are telling the reflection system to serialize this property whenever it changes on the server and transmit that serialized data to all connected clients. Because the reflection system already knows the type and memory layout of CurrentHealth (thanks to the UPROPERTY macro), it can handle the low-level serialization automatically.

Once the client receives this packet, the engine uses the same reflection data to write the value directly into the memory address of the corresponding UPROPERTY on the client’s version of that Actor. This keeps both the server and the client in perfect sync without you needing to write manual networking code for every single variable.

Remember, always ensure your class has a GetLifetimeReplicatedProps function implemented in the .cpp file, as this is the "bridge" that formally registers these reflected properties with the replication system.

Key Takeaway: By adding the Replicated specifier to a UPROPERTY, you leverage the reflection system to automate the serialization and transmission of data from the server to client instances.