PersistentStateCodec
The state blob of a PersistedEntityRecord: every PersistAttribute NetworkVariable and every behaviour's NetworkBehaviour.WritePersistentState chunk, each under a name.
Nebula · Packages/com.1by3.nebula/Runtime/Persistence/PersistentStateCodec.cspublic static class PersistentStateCodecThe state blob of a PersistedEntityRecord: every PersistAttribute NetworkVariable and every behaviour's NetworkBehaviour.WritePersistentState chunk, each under a name.
Named entries rather than a positional layout, because a save outlives the build that wrote it: a variable that was removed is skipped on read, one that was added keeps its default, and a renamed behaviour simply starts fresh. Each entry is length-prefixed and read through a reader bounded to its own bytes, so a behaviour that reads too much fails inside its chunk (logged) instead of corrupting the next entry.
[version:byte=1][count:ushort] { [name:string][length:ushort][bytes] }Pure functions over a NetworkIdentity: no worker, no store, no scene.
Fields
Version
public const byte Version = 1;Format version written at the head of every blob. A blob with a newer version is ignored on read.
BehaviourStateSuffix
public const string BehaviourStateSuffix = "#state";Suffix of the entry holding a behaviour's own NetworkBehaviour.WritePersistentState bytes.
Methods
StateNameOf
public static string StateNameOf(NetworkBehaviour behaviour);The entry name of a behaviour's own state chunk.
Write
public static void Write(NetworkWriter writer, NetworkIdentity identity);
public static byte[] Write(NetworkIdentity identity);Write identity's persistent state. Also clears the per-variable dirty flags: what is in the blob has been captured, whatever the store then does with the record.
Read
public static void Read(NetworkReader reader, NetworkIdentity identity);
public static void Read(byte[] state, NetworkIdentity identity);Apply a blob to identity. Entries are matched by name: unknown ones are skipped and missing ones leave the entity's own defaults. Reading a variable fires its OnValueChanged, which is what a restored entity wants.
TryReadEntry
public static bool TryReadEntry(byte[] state, string name, out ArraySegment<byte> entry);Read one named entry out of a state blob without an entity to apply it to: the bytes a behaviour wrote (name StateNameOf, i.e. TypeName#state) or one persisted variable, exactly as Read would have handed them over. For a game inspecting a PersistedEntityRecord it loaded — an entity not spawned on this worker, or not spawned at all — instead of duplicating the blob layout. Returns false for a null/empty blob, a blob written by a newer build, or a name that is not present.
TryReadBehaviourState
public static bool TryReadBehaviourState(byte[] state, string behaviourTypeName, out ArraySegment<byte> entry);TryReadEntry for a behaviour's own state chunk, named by behaviour type name (without the BehaviourStateSuffix).
HasDirtyVars
public static bool HasDirtyVars(NetworkIdentity identity);True when any PersistAttribute variable of identity changed since the last Write.
PersistentEntity
Put this on a prefab or a scene object to make the entity outlive the process that simulates it.
RemotePersistenceStore
IPersistenceStore for a worker: every save and load goes to the orchestrator, which owns the real store (PersistenceHost over the dashboard address, the same one the control plane uses).