Nebula
Core

SyncStateCodec

Envelope shared by the per-tick sync stream (EntityState/GhostSyncState messages) and the spawn snapshot: [count]{[behaviourIndex][flags][len:ushort][chunk]}.

generated from the sources
Static class in namespace Nebula · Packages/com.1by3.nebula/Runtime/Core/SyncState.cs
public static class SyncStateCodec

Envelope shared by the per-tick sync stream (EntityState/GhostSyncState messages) and the spawn snapshot: [count]{[behaviourIndex][flags][len:ushort][chunk]}. Each chunk is bounded so a behaviour that reads too much or too little cannot corrupt its neighbours. Kept free of NetworkIdentity so the gateway can cache keyframes without instantiating anything.

Methods

AudienceOf

public static SyncAudience AudienceOf(ChunkFlags flags);

The audience a chunk's flags carry.

FlagsOf

public static ChunkFlags FlagsOf(SyncAudience audience);

The flag bits that carry audience; none for SyncAudience.Everyone.

IsRestricted

public static bool IsRestricted(ChunkFlags flags);

Whether the flags name an audience that limits which clients receive the chunk (anything but SyncAudience.Everyone).

BeginEnvelope

public static int BeginEnvelope(NetworkWriter w);

EndEnvelope

public static void EndEnvelope(NetworkWriter w, int countAt, byte count);

WriteChunk

public static void WriteChunk(NetworkWriter w, byte behaviourIndex, ChunkFlags flags, NetworkBehaviour b, bool full);

WriteRawChunk

public static void WriteRawChunk(NetworkWriter w, byte behaviourIndex, ChunkFlags flags, ArraySegment<byte> chunk);

ReadEnvelope

public static void ReadEnvelope(NetworkReader r, ChunkVisitor visit);

Nested types

ChunkFlags

[Flags]
public enum ChunkFlags : byte

Lists the supported chunk flags values.

Members

NameValueDescription
None0
Full1The chunk is a keyframe: everything the behaviour replicates, not just what changed.
AudienceOwner1 << 1Bits 1 and 2 hold the behavior's SyncAudience (AudienceMask). Zero is SyncAudience.Everyone, so a chunk of an unrestricted behavior is byte for byte what it was before audiences existed. The gateway filters on these bits; workers and clients ignore them.
AudienceWorkersOnly2 << 1See AudienceOwner: the chunk is for workers only.
AudienceCustom3 << 1See AudienceOwner: the chunk is for the member set the authority sent (SyncAudienceMsg).
AudienceMask3 << 1The two audience bits.
Cleared1 << 3Gateway to client, protocol 20 and later: this client left the behavior's audience. The chunk is empty. The client calls NetworkBehaviour.OnSyncStateCleared instead of ReadSyncState.
DistanceRated1 << 4Worker to gateway: the behavior's state follows the entity's distance tier (SyncDistanceRating, docs/server-owned-entities.md D11). The gateway sends such a chunk to a client beyond its every-update band only as a keyframe, one per window of the client's rate. Clients ignore the bit.
Settled1 << 5Worker to gateway, with DistanceRated and Full, on the reliable stream: the keyframe a rated behavior writes once it has stopped changing. The gateway sends it to every client that holds the entity, whatever its distance, so a coalesced client ends with the latest state. Clients ignore the bit.

ChunkVisitor

public delegate void ChunkVisitor(byte behaviourIndex, ChunkFlags flags, ArraySegment<byte> chunk);

On this page