Nebula
Worker

NebulaWorker

The sim worker: a headless Unity process leased authority over a set of containers.

generated from the sources
public sealed class NebulaWorker : MonoBehaviour, IRpcSink

The sim worker: a headless Unity process leased authority over a set of containers. It simulates the entities in those containers at the tick rate, ghosts entities approaching a neighbouring container to that container's worker over the lateral link, hands authority over when they cross, and streams its authoritative entities to the gateway. One process can own any number of containers; adjacent containers on the same worker hand over locally with no network traffic at all.

Fields

StateBatchBytes

public const int StateBatchBytes = 500;

Byte budget for one Sequenced world/ghost-state packet. Sequenced delivery cannot fragment, and a peer's MTU starts at LiteNetLib's floor (508 bytes) until discovery finishes, so batches are cut by size rather than by entry count. At 36 bytes per entry this is 13 entries per packet.

MaxCatchUpTicks

public const int MaxCatchUpTicks = 2;

Most ticks the loop is allowed to simulate in one FixedUpdate to catch up with the wall clock. Beyond this the missing tick numbers are skipped (everything runs a little slow for a moment) rather than simulated back-to-back, which would only push the next frame further behind.

Properties

Config

public NebulaConfig Config { get; }

ControlPlane

public IControlPlane ControlPlane { get; }

WorkerId

public string WorkerId { get; }

WorkerIndex

public ushort WorkerIndex { get; }

Port

public ushort Port { get; }

IsListening

public bool IsListening { get; }

CurrentTick

public uint CurrentTick { get; }

TickCount

public ulong TickCount { get; }

TickMs

public float TickMs { get; }

HandoversOut

public int HandoversOut { get; }

HandoversIn

public int HandoversIn { get; }

LocalHandovers

public int LocalHandovers { get; }

GhostsSent

public int GhostsSent { get; }

GhostsHeld

public int GhostsHeld { get; }

AuthoritativeCount

public int AuthoritativeCount { get; }

EntityCount

public int EntityCount { get; }

PlayerCount

public int PlayerCount { get; }

Authoritative entities owned by human clients / by bot clients / by nobody (server-driven), as of the last heartbeat.

BotCount

public int BotCount { get; }

ServerDrivenCount

public int ServerDrivenCount { get; }

Entities

public IEnumerable<NetworkIdentity> Entities { get; }

Authoritative

public IReadOnlyList<NetworkIdentity> Authoritative { get; }

MeshReady

public bool MeshReady { get; }

Every container's owner is connected to this worker (or is this worker). Game code that spawns into containers it does not own should wait for this: the immediate handover needs a target.

IsRegistered

public bool IsRegistered { get; }

Registered with the control plane; the mesh knows about this worker.

Events

EntitySpawned

public event Action<NetworkIdentity> EntitySpawned;

EntityDespawned

public event Action<NetworkIdentity> EntityDespawned;

AuthorityHandedOff

public event Action<NetworkIdentity, string> AuthorityHandedOff;

AuthorityReceived

public event Action<NetworkIdentity, string> AuthorityReceived;

Methods

Initialize

public void Initialize(NebulaConfig config, IControlPlane controlPlane);

Spawn

public void Spawn(NetworkIdentity identity, Container container, uint ownerClientId = 0);

Allocate an id and make identity live on this worker. Call after instantiating a network prefab.

SpawnServerDriven

public void SpawnServerDriven(NetworkIdentity identity, Container container);

Spawn a server-driven entity: one with no owning client whose PredictedBehaviour<TInput> (if any) gets its input from GatherServerInput on whichever worker holds authority. It ghosts and hands over like any other entity and costs nothing beyond the entity itself. The container need not be owned by this worker: the mesh hands the entity to its owner on the next tick (see MeshReady).

SpawnPrefab

public NetworkIdentity SpawnPrefab(GameObject prefab, Vector3 position, Quaternion rotation, Container container, uint ownerClientId = 0);

Despawn

public void Despawn(NetworkIdentity identity);

Find

public NetworkIdentity Find(ulong netId);

FindPlayer

public NetworkIdentity FindPlayer(uint clientId);

On this page