In this lesson, you will learn how to optimize bandwidth by synchronizing only the modified portions of complex data structures using NetDeltaSerialization.
The Problem with Full Replication
When you replicate a struct or TArray in Unreal, the engine typically replicates the entire object whenever any single member changes. If you have a large FInventoryData struct, updating a single integer inside it would force the server to send the full struct over the wire. As your game scales, this "all-or-nothing" approach consumes significant bandwidth.
Leveraging NetDeltaSerialization
NetDeltaSerialization allows you to track changes at the field level, serializing and transmitting only the "delta"—the difference between the previous state and the current state. This is achieved by implementing the NetDeltaSerialize function within your struct.
When you override NetDeltaSerialize, the engine provides you with a FNetDeltaSerializeInfo object. You use this to track which bits have changed using DeltaParms.Writer.
bool FMyStateStruct::NetDeltaSerialize(FNetDeltaSerializeInfo& DeltaParms)
{
// Mark the property as dirty if the value has changed
if (DeltaParms.Writer)
{
// Only write the specific field that changed
DeltaParms.Writer->WriteBit(bIsActiveChanged);
if (bIsActiveChanged)
{
DeltaParms.Writer->WriteBit(bIsActive);
}
}
else if (DeltaParms.Reader)
{
// Read only the transmitted bits
DeltaParms.Reader->ReadBit(bIsActiveChanged);
if (bIsActiveChanged)
{
DeltaParms.Reader->ReadBit(bIsActive);
}
}
return true;
}
Why it Matters
By using this technique, you move away from full-object updates. Instead of the network traffic scaling with the size of your structure, it scales only with the frequency and volume of the changes themselves. This is essential for high-frequency updates, such as synchronization of complex equipment states or shared tactical information in high-player-count sessions.
When implementing this, ensure your struct supports bitwise comparisons to track which elements are "dirty," allowing the Writer to skip over unmodified data entirely.
Key Takeaway: NetDeltaSerialization transforms bandwidth-heavy property replication into surgical updates, ensuring that only the specific bits that changed are sent across the network.