CharacterNetwork

Synchronizes character state across the network — movement, look direction, sprint state, and interactions. Handles ownership transfer for interactables and replicates interaction input via RPCs.

Definition

Namespace: Paragon.Townskeep.CharacterSystem Assembly: Townskeep.dll

public class CharacterNetwork : ParagonNetworkBehaviour, IParagonComponent<Character>

Inheritance: NetworkBehaviourParagonNetworkBehaviourCharacterNetwork Implements: IParagonComponent<Character>

Remarks

CharacterNetwork is the networking backbone of the Character system. Unlike other character services that extend CharacterComponent (a serializable subsystem component), this class extends ParagonNetworkBehaviour directly because it must be a MonoBehaviour on the character's GameObject for Unity Netcode to manage it.

It implements IParagonComponent<Character> to participate in the Character's component lifecycle (OnAdded, OnRemoved, Initialize).

Synchronization Strategy

The class uses two complementary sync mechanisms:

  1. NetworkVariable<SyncData> — Continuous state sync (position, rotation, sprint, look direction). The owner writes every Update(); non-owners read and apply to the character controller.

  2. RPCs — Discrete event sync (interaction begin/end, interaction inputs). Sent NotOwner so all remote clients replicate interactions.

  3. OnSynchronize — Initial state synchronization when a new client joins. Serializes all active interactions so late-joiners can reconstruct interaction state.

Interaction Networking Flow

spinner

Quick Lookup

Goal
How

Access owner character

IParagonComponent<Character>.Owner (explicit interface)

Check if local player owns this

IsOwner (from NetworkBehaviour)

Get client ID

ClientID (static, from ParagonNetworkBehaviour)

Methods

Awake

Initializes the NetworkVariable<SyncData>, SyncData struct, and input callbacks dictionary.

Initialize

Subscribes to the character's interaction system events (InteractionBegin, InteractionEnd).

OnAdded

Called when this component is added to a Character. Stores the character reference.

Parameter
Type
Description

character

Character

The owning character

OnRemoved

Called when this component is removed from a Character. Clears the character reference.

OnSynchronize (override)

Handles initial state sync for late-joining clients. Serializes/deserializes all active interactions with their network object references.

circle-info

Late-join deserialization uses Yield.WaitForEndOfFrame() to ensure NetworkObject references are resolved before attempting interaction replay.

BeginInteractionRpc

Replicates an interaction start to non-owner clients.

EndInteractionRpc

Replicates an interaction end to non-owner clients.

InputRpc

Replicates an interaction input press to non-owner clients.

Parameter
Type
Description

networkObjectReference

NetworkObjectReference

Reference to the interactable's network object

inputName

string

Name of the InteractionInput to invoke

Update

Per-frame sync loop. Owner writes SyncData to the NetworkVariable; non-owners read and apply movement to the character's controller.

Nested Types

SyncData

Network-serializable struct containing the character's synchronized movement state.

Field
Type
Description

TargetPose

Pose

Target position and rotation

IsRunning

bool

Whether the character is sprinting

LookAt

Vector3

Camera look direction

Common Pitfalls

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

See Also

Last updated