Skip to content

Sein State Writer

C++ type · FSeinStateWriter

#include "State/SeinStateArchive.h"

The byte streams for simulation state. One writer serves save files, reconnect transfer, replay checkpoints and the desync checksum.

A capture has two streams. The state stream holds everything the simulation reads; the checksum hashes it, so it is identical on every peer. The presentation stream holds what only presentation reads: text, references to presentation assets (textures, materials, sounds, meshes, effects), float and double fields, and delegate bindings whose target is not a sim object (a HUD widget, say). It is saved and restored exactly but never hashed, because text renders per language and a dedicated server may not load presentation assets. Pack joins the two streams; FSeinStateReader splits them.

Values are written through reflection. Numbers, enums and bools are copied raw (little-endian); names and gameplay tags go through a per-chunk string table; maps and sets are sorted by key so their bytes never depend on hash order. Transient, editor-only and deprecated properties are skipped.

The state stream starts with an object table, then a list of chunks. A reference to an asset, class, world subsystem or sim object (any other object owned by the world or the transient package) is an index into the table; the table says how to find or create each object, and each entry refers only to earlier ones. Sim objects’ properties and Blueprint event-graph frames are written in body chunks, then delegate bindings in delegate chunks, once every object is known: a binding is state exactly when the state references its target. References to actors and actor components are errors in the state stream. Delegates are allowed only on sim objects. The presentation stream lists each chunk’s presentation size, so editing presentation never changes a checksummed byte.

Chunks are independent, so they are written on worker threads: their boundaries depend only on the data, never on thread count, and the bytes are the same either way.

C++ members (18)
  • void WriteStruct(const UScriptStruct* Type, const void* Data);
  • void WriteProperty(const FProperty* Property, const void* Container); Write one property (every static-array element) of a container.
  • void WriteObjectState(const UObject* Object); Write an object’s own state (not a reference to it), for comparing two objects of the same class.
  • void WriteObject(const UObject* Object);
  • void WriteName(FName Name);
  • void WriteString(const FString& String);
  • void WriteBytes(const void* Data, int32 Size);
  • void NextChunk(); Close the current chunk; later writes start a new one. Readers call FSeinStateReader::NextChunk at the same point.
  • void WriteChunksInParallel(int32 Count, TFunctionRef<void(int32 Index, FSeinStateWriter& Chunk)> Encode); Write Count chunks on worker threads, each through its own writer, in index order. Writes after this start a new chunk. Readers call NextChunk before each of these chunks and once more after the last.
  • void FlushObjects(); Write the body of every sim object referenced so far, including objects first referenced from those bodies, then all delegate bindings, and finish the streams. Call once, after the last root value.
  • bool HasError() const;
  • const FString& GetError() const;
  • const TArray<uint8>& GetBytes() const; The state stream: what the checksum hashes. Valid after FlushObjects.
  • const TArray<uint8>& GetPresentationBytes() const;
  • FGuid GetChecksum() const; SeinStateChecksum of the state stream. Valid after FlushObjects.
  • TArray<uint8> Pack() const; Both streams in one buffer, as FSeinStateReader expects them.
  • const TSet<const UStruct*>& GetWrittenTypes() const; Every struct and class whose layout this writer used.
  • TArray<TPair<const UObject*, FGuid>> GetObjectChecksums() const; Each sim object the stream wrote a body for, in table order, with the checksum of its own state. Comparing two peers’ lists names the object a desync changed. Valid after FlushObjects.