PlayerNetwork
Network component for the Player. Handles player identity initialization, sets Player.Current for the local client, and synchronizes possession state across the network via RPCs and OnSynchronize for late-joining clients.
Definition
Namespace: Paragon.Townskeep.PlayerSystem
Assembly: Townskeep.dll
public class PlayerNetwork : ParagonNetworkBehaviourInheritance: NetworkBehaviour → ParagonNetworkBehaviour → PlayerNetwork
Remarks
PlayerNetwork serves three key roles:
1. Player identity initialization
Initialize(NetworkPlayer) is called by the network layer when a player joins. It sets the GameObject name to "Player [username]" and, for the local client, sets Player.Current and enables input processing.
2. Possession synchronization
On OnNetworkSpawn, the component subscribes to the sibling Possessor's Possessed and Released events. When the owner possesses or releases an entity:
Owner side — Requests ownership of the possessed
NetworkObject(if not already owned), then sends an RPC to non-authority clientsNon-authority side — Receives the RPC and replicates the
Possess()/Release()call locally
3. Late-join state synchronization
OnSynchronize serializes all current possessions as NetworkObjectReference entries. Late-joining clients deserialize and replay the possessions via Yield.WaitForEndOfFrame() to ensure network objects are resolved.
Possession Network Flow
Quick Lookup
Initialize with network player
playerNetwork.Initialize(networkPlayer)
Check if local client
networkPlayer.ClientID == ClientID
Access static client ID
ParagonNetworkBehaviour.ClientID
Methods
Awake
Caches the Player and Possessor sibling components.
Initialize
Binds the player to a NetworkPlayer identity. Sets the GameObject name and, for the local client, assigns Player.Current and enables PlayerInput.
networkPlayer
NetworkPlayer
The network identity for this player
OnNetworkSpawn (override)
Subscribes to Possessor.Possessed and Possessor.Released events for network synchronization.
OnSynchronize (override)
Handles late-join synchronization. Writes all current possessions as NetworkObjectReference entries; reads and replays possessions on the receiving end.
Late-join deserialization uses Yield.WaitForEndOfFrame() to ensure NetworkObject references are resolved before attempting to possess.
OnPossessedRpc
Replicates a possession to non-authority clients.
OnReleasedRpc
Replicates a release to non-authority clients.
OnNetworkDespawn (override)
Unsubscribes from Possessor.Possessed and Possessor.Released events.
Common Pitfalls
Player.Current is only set for the local client
Initialize() only assigns Player.Current when networkPlayer.ClientID == ClientID. On remote clients and the server, Player.Current remains unchanged.
Ownership transfer on possession
When the owner possesses an entity, ChangeOwnership(ClientID) is called on the possessed NetworkObject if the player doesn't already own it. This assumes the server grants ownership transfers — if the server rejects, the possession will be out of sync.
RPCs use SendTo.NotAuthority
Unlike CharacterNetwork which uses SendTo.NotOwner, this class uses SendTo.NotAuthority. This means the RPC is sent to all clients except the authority (server/host for server-authoritative, or owner for owner-authoritative).
Event subscription lifetime
Events are subscribed in OnNetworkSpawn and unsubscribed in OnNetworkDespawn. If the Possessor fires events outside this window, they will not be networked.
See Also
Player — the player entity this network component serves
PlayerInput — enabled by this component for local clients
Possessor — the possession component whose events are networked
ParagonNetworkBehaviour — base class providing network + debug integration
Last updated