Network Component
plNetworkComponent is the base class for all components that participate in network replication. It provides the core infrastructure for serialization, dirty tracking, channel configuration, and authority awareness.
Overview
Any component that needs to replicate state across the network should inherit from plNetworkComponent. The base class handles:
Registration with the
plNetworkWorldModuleon startup.Automatic serialization of properties marked with
plNetSerializeAttribute.Dirty flagging so the replication loop knows when to send updates.
Network role and channel type configuration.
Ownership and authority queries.
Inheriting from plNetworkComponent
In the reflection block, mark properties for replication:
Serialization
By default, NetworkSerialize() and NetworkDeserialize() use plNetworkSerializer to automatically serialize all properties that have the plNetSerializeAttribute. You can override these methods for custom serialization:
Dirty Tracking
The replication loop only sends updates for components that have been marked dirty. Call MarkDirty() whenever a replicated property changes:
The replication loop calls ClearDirty() after sending the update.
Network Role
Each component has a network role that determines which machines it is active on:
Channel Type
Control the delivery guarantee for this component's replication:
Ownership
Check if the local machine owns this component's game object:
Replication Conditions
If any properties use advanced replication conditions (e.g., OnChange, OwnerOnly), the component automatically uses the context-aware serialization path:
See Network Serialization for details on replication conditions.
Network ID
Every registered network component is assigned a unique network ID:
This ID is used internally for message routing and RPC targeting.
Lifecycle Callbacks
plNetworkComponent provides virtual callbacks for low-level connection events:
Callback | When Called |
|---|---|
| Connection state changes (connected, disconnected, etc.) |
| A client is in the process of connecting |
| A client has successfully connected |
| A client has disconnected |
Network Message Handlers
In addition to the low-level callbacks above, plNetworkComponent registers PL_MESSAGE_HANDLER entries for all high-level network events. These are delivered through the standard plMessage system. Override any of them in your subclass:
Handler | Message Type | When Called |
|---|---|---|
|
| A player joins the session |
|
| A player leaves the session |
|
| Session state transitions (Lobby, InGame, etc.) |
|
| All players marked ready |
|
| Server requests a level load |
|
| Server signals gameplay can begin |
|
| All clients finished level loading |
|
| A client connects to the server |
|
| A custom user message (IDs 128-255) is received |
|
| Server is about to spawn an object (set |
|
| A network object was spawned (server and client) |
Example:
All message types are defined in NetworkPlugin/Core/NetworkMessages.h.