Skip to content

Saves and Replays

A SeinARTS match is fully described by one thing: its world state. Everything the simulation owns lives in it, and one serializer writes it as bytes. Saved games, replay checkpoints, the state a returning player receives and the checksum that detects a desync all use those same bytes. You write no save code for them.

Replays add a second idea. Because the simulation is deterministic, a match is also fully described by its starting state plus the commands players issued. A replay stores the commands and plays them back through the real simulation.

The world state holds the tick count, the random stream, the match and its players, every entity with its components and tags, the ability and effect objects entities own, and the state of modules such as navigation. Caches that can be rebuilt from it, such as the spatial index, are not saved. They are rebuilt after a load.

New simulation data joins the world state automatically when it is a component, a property of an ability or effect, or part of a module’s registered state. See Deterministic Simulation.

The serializer writes two streams:

  • The state stream holds everything the simulation reads. The desync checksum covers it, so it is identical on every machine.
  • The presentation stream holds what only presentation reads: text, references to textures, meshes, materials, sounds and effects, and numbers marked Presentation. It is saved and restored exactly, but excluded from the checksum.

This split lets players run different languages, and lets a dedicated server skip presentation assets, without ever causing a desync.

Some things cannot be in the world state. A reference to an actor or an actor component in simulation data is an error: actors belong to one machine, and the simulation cannot own them. Delegates are allowed only on objects the simulation owns.

In a standalone game, Save Match writes the world state and the local camera to a file. Load Match reads a file back and the match continues from the saved tick, with the camera where it was.

A load rebuilds the match around the saved state:

  1. The file is read into a fresh state and checked before the live match is touched. A bad file leaves the match running as it was and Load Match returns false.
  2. The old match is dropped. It does not get cancelled, removed or destroyed events, because it will never run again.
  3. Visual events still waiting to play are discarded.
  4. Unit actors are reconciled with the new state: actors for units that no longer exist are removed, actors for missing units are spawned, and the rest are told to refresh. Their On Presentation Refresh event fires so their look can be set from current data, without replaying the one-shot effects that led there.
  5. The simulation resumes.

Save Match and Load Match return false in a network match. A load rewinds only one machine, so it would desync the others.

Where the file goes: a relative name is saved under Saved/Snapshots in the game’s folder, with .seinsnapshot added when the name has no file type.

Every save and replay carries a compatibility header, and a file loads only where all of it matches:

Part Changes when
Format version The framework changes the state layout.
Build identity The framework version, the project version, or any simulation content changes.
Simulation settings hash You change a simulation-affecting setting.
Map The file was made on a different map.

The simulation content in the build identity is every map, user-defined struct and enum, data table, curve table, data asset and Blueprint except widgets and animation. Textures, meshes, materials, sounds, widgets and animation do not count. Editing a unit Blueprint, a data table or an ability invalidates old saves and replays. Retexturing it does not.

An editor process records its content as “Uncooked”, so files made in the editor load only in the editor, and files made by a packaged game load only in a packaged game of the same build. Bump the project version when you want old files rejected on purpose.

A replay file holds:

  • The match settings and the seed it started from.
  • Every turn’s commands.
  • A state checkpoint at turn 0, and another every Checkpoint Interval (turns) turns (3000 by default, five minutes at the default turn rate).
  • The desync checksum at every check turn, and the tick and checksum at which the match ended.
  • The resumes that ended each pause, which travel outside turns.

The host records every match it plays through the network layer, automatically. The file is written as a .tmp file in Saved/Replays and renamed Replay_<date>_<time>.seinreplay when the match ends, aborts, or you run Sein.Net.SaveReplay. The Maximum File Size (MiB) setting caps one recording at 16,384 MiB by default: recording stops before crossing it.

A standalone game that is not hosted does not record. Matches run through the lobby’s Host flow do, including matches against the computer.

Camera and selection records are kept in the command stream as observer commands. They change nothing in the simulation. They keep what a player looked at in the recording.

Playback runs in a standalone game, on the map the replay was recorded on. It restores the nearest checkpoint, then feeds the recorded commands to the real simulation. Local input never reaches a replay, so the player watches.

Playback also checks itself. At each recorded check turn, and at the end, it compares its own checksum with the recorded one. A mismatch is logged, and on stopping, the log counts how many matched and how many differed. A replay that differs from its recording on the same build means the simulation read something that is not in its state or commands. That makes a replay a determinism test as well as a viewer.

Seeking to turn T restores the latest checkpoint at or before T and runs forward from there to T as fast as it can, up to Max Ticks Per Frame ticks per rendered frame. A smaller checkpoint interval makes seeks faster, and costs disk space.

A 20-minute match is 12,000 turns at the defaults. The recording holds checkpoints at turns 0, 3000, 6000 and 9000.

A viewer drags the timeline to minute 13, which is turn 7,800. Playback restores the checkpoint at turn 6,000 and runs the 1,800 turns between, 5,400 ticks. At the default Max Ticks Per Frame of 5 and 60 frames per second, that takes about 18 seconds. With a checkpoint every 600 turns, the nearest one is turn 7,800 itself and the seek is instant.

  • Keeping actor pointers in simulation data, or delegates in a component. The match build or the save fails with an error naming the reference.
  • Storing a float in a component. Mark it Presentation if only visuals read it. Otherwise use a fixed-point type.
  • Expecting UI and effects to be in a save. Widgets, particles and sounds belong to presentation. After a load, rebuild them from the world state in the On Presentation Refresh handler.
  • Shipping a patch and expecting old replays to play. Any simulation content change makes the build identity differ.
  • Loading a save on another map. The header names the map and refuses.