Network Serialization
The plNetworkSerializer provides automatic, reflection-based property serialization for network components. Properties marked with plNetSerializeAttribute are discovered via RTTI, cached per type, and serialized with optional quantization and replication conditions.
Overview
Instead of writing manual NetworkSerialize()/NetworkDeserialize() overrides, you can annotate properties in the reflection block and let the serializer handle the rest:
plNetSerializeAttribute
This attribute marks a property for network serialization. It supports several options:
Encoding
Encoding | Description | Use Case |
|---|---|---|
| Full precision (standard Variant serialization) | Most properties |
| Half-float (16-bit) for floats and vectors | Positions, velocities |
| Compressed quaternion (smallest 3 components) | Rotations |
Replication Conditions
Control when a property is sent:
Condition | Description |
|---|---|
| Send every replication tick (default) |
| Send only when the value differs from the last sent value |
| Send only during initial synchronization (late-joiner) |
Replication Targets
Control who receives a property:
Target | Description |
|---|---|
| Send to all clients (default) |
| Send only to the owning client |
| Send to all clients except the owner |
Helper Macros
The plugin provides convenience macros for common patterns:
Macro | Encoding | Condition | Target | Visible in Editor |
|---|---|---|---|---|
| Default | Always | AllClients | No |
| Half | Always | AllClients | No |
| SmallestThree | Always | AllClients | No |
| Default | Always | AllClients | Yes |
| Half | Always | AllClients | Yes |
| SmallestThree | Always | AllClients | Yes |
| Default | InitialOnly | AllClients | No |
| Default | OnChange | AllClients | No |
| Default | Always | OwnerOnly | No |
| Default | Always | NonOwner | No |
Explicit Attribute Construction
For full control, construct the attribute manually:
Wire Format
Basic Format (No Conditions)
Used when a component has no replication conditions:
All properties are always sent.
Context-Aware Format (With Conditions)
Used when a component has OnChange, InitialOnly, OwnerOnly, or NonOwner properties:
Each bit in the bitmask corresponds to a property (in reflection order). Only properties whose bit is set are included in the payload. This reduces bandwidth when using OnChange conditions.
Per-Recipient Serialization
When a component has OwnerOnly or NonOwner properties, the replication loop performs per-client serialization. For each connected client, the serializer evaluates which properties should be included based on whether the client is the owner. This means different clients may receive different subsets of properties.
Components without per-recipient properties are serialized once and broadcast to all clients.
OnChange Tracking
When plReplicateCondition::OnChange is used, the serializer maintains a cache of last-sent values per component. Each tick, it compares the current value against the cached value and only includes the property if it has changed. After sending, the cache is updated.
Custom Serialization
If automatic serialization does not meet your needs, override NetworkSerialize() and NetworkDeserialize() on your component: