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 : ParagonNetworkBehaviour

Inheritance: NetworkBehaviourParagonNetworkBehaviourPlayerNetwork

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 clients

  • Non-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

spinner

Quick Lookup

Goal
How

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.

Parameter
Type
Description

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.

circle-info

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

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

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