NetworkBehaviour
Base class for meshed gameplay code.
Nebula · Packages/com.1by3.nebula/Runtime/Core/NetworkBehaviour.cs[RequireComponent(typeof(NetworkIdentity))]
public abstract class NetworkBehaviour : MonoBehaviourBase class for meshed gameplay code. The surface is deliberately the one Mirror/NGO users know: IsServer/IsClient/IsOwner, spawn/despawn hooks, NetworkVariables and RPCs. The meshing-specific additions are small: HasAuthority (this worker owns the entity right now), IsGhost (this worker holds a kinematic replica owned by a neighbour), OnGainedAuthority/OnLostAuthority, and AuthorityRpc.
Properties
Identity
public NetworkIdentity Identity { get; }BehaviourIndex
public byte BehaviourIndex { get; }NetId
public ulong NetId { get; }IsSpawned
public bool IsSpawned { get; }IsServer
public bool IsServer { get; }IsClient
public bool IsClient { get; }IsOwner
public bool IsOwner { get; }Client side: this is the local player's entity.
HasAuthority
public bool HasAuthority { get; }Server side: this worker is authoritative for the entity right now.
IsGhost
public bool IsGhost { get; }Server side: this worker holds a non-authoritative replica driven by a neighbouring worker.
OwnerClientId
public uint OwnerClientId { get; }Container
public Container Container { get; }HasSyncState
public virtual bool HasSyncState { get; }True when this behaviour replicates through WriteSyncState/ReadSyncState.
SyncDelivery
public virtual Delivery SyncDelivery { get; }Delivery for this behaviour's sync chunks. Unreliable (sequenced) is right for transforms: a lost delta is healed by the next keyframe. Reliable is right for anything a receiver must not miss (animator triggers).
Methods
OnNetworkSpawn
public virtual void OnNetworkSpawn();OnNetworkDespawn
public virtual void OnNetworkDespawn();OnGainedAuthority
public virtual void OnGainedAuthority();Called on a worker when it becomes authoritative for this entity (spawn, or handover in).
OnLostAuthority
public virtual void OnLostAuthority();Called on a worker when authority moves to a neighbour. The object stays alive as a ghost.
OnContainerChanged
public virtual void OnContainerChanged(Container previous, Container current);OnOriginShifted
public virtual void OnOriginShifted(Vector3 delta);Partitioned worlds: the floating origin moved by delta. The transform was moved with its container; add the delta to any frame position this behaviour caches itself (a target, a path, a history buffer). Not called in single-scene games.
NetworkTick
public virtual void NetworkTick(uint tick, float deltaTime);Authoritative simulation step at the network tick rate. Not called for ghosts or on clients.
WriteHandoverState
public virtual void WriteHandoverState(NetworkWriter writer);Called on the outgoing worker while building an authority transfer, before OnLostAuthority. Write any state the next owner needs that is not already replicated (angular velocity, timers, RNG state...). Travels only with the handover, never in the per-tick stream. Must be mirrored exactly by ReadHandoverState.
ReadHandoverState
public virtual void ReadHandoverState(NetworkReader reader);Called on the incoming worker after the entity's pose, velocity and NetworkVariables have been applied and before OnGainedAuthority. Read exactly what WriteHandoverState wrote.
MarkSyncDirty
protected void MarkSyncDirty();Ask the worker to send this behaviour's sync state at the end of the tick.
WriteSyncState
public virtual void WriteSyncState(NetworkWriter writer, bool full);Authority only. Write the state to replicate. When full is true write everything (a keyframe: this is what a late joiner or a fresh ghost will start from); otherwise only what changed since the last write is needed, though writing everything is always correct.
ReadSyncState
public virtual void ReadSyncState(NetworkReader reader, uint tick, bool full);Non-authoritative copies. tick is the simulation tick the state belongs to (0 for a spawn snapshot); buffer it and present it from RemoteTick, or apply it at once.
OnSyncStateSent
protected internal virtual void OnSyncStateSent();The tick's sends are done (every peer and gateway got this tick's chunk): drop per-tick pending deltas. Called from NetworkIdentity.ClearDirty; the owning client calls it after its own send.
RemoteTick
public virtual void RemoteTick(double renderTick);Called on every copy this process does not simulate (ghosts on a worker: once per tick before physics syncs; entities on a client: once per frame) with the tick to present. Interpolating behaviours sample their buffers here. See NetworkTime.RenderTick.
ClientRpc
protected void ClientRpc(Action method);
protected void ClientRpc<T1>(Action<T1> method, T1 a1);
protected void ClientRpc<T1, T2>(Action<T1, T2> method, T1 a1, T2 a2);
protected void ClientRpc<T1, T2, T3>(Action<T1, T2, T3> method, T1 a1, T2 a2, T3 a3);
protected void ClientRpc<T1, T2, T3, T4>(Action<T1, T2, T3, T4> method, T1 a1, T2 a2, T3 a3, T4 a4);OwnerRpc
protected void OwnerRpc(Action method);
protected void OwnerRpc<T1>(Action<T1> method, T1 a1);
protected void OwnerRpc<T1, T2>(Action<T1, T2> method, T1 a1, T2 a2);
protected void OwnerRpc<T1, T2, T3>(Action<T1, T2, T3> method, T1 a1, T2 a2, T3 a3);A ClientRpc delivered only to the entity's owning client.
ServerRpc
protected void ServerRpc(Action method);
protected void ServerRpc<T1>(Action<T1> method, T1 a1);
protected void ServerRpc<T1, T2>(Action<T1, T2> method, T1 a1, T2 a2);
protected void ServerRpc<T1, T2, T3>(Action<T1, T2, T3> method, T1 a1, T2 a2, T3 a3);AuthorityRpc
protected void AuthorityRpc(Action method);
protected void AuthorityRpc<T1>(Action<T1> method, T1 a1);
protected void AuthorityRpc<T1, T2>(Action<T1, T2> method, T1 a1, T2 a2);
protected void AuthorityRpc<T1, T2, T3>(Action<T1, T2, T3> method, T1 a1, T2 a2, T3 a3);
protected void AuthorityRpc<T1, T2, T3, T4>(Action<T1, T2, T3, T4> method, T1 a1, T2 a2, T3 a3, T4 a4);