ReplaySave
Lean save record that captures the minimum state needed to reconstruct a full conversation session via deterministic replay. Obtain a populated instance by calling Save() (struct form) or serialize directly to JSON via SaveToJson(). To restore, pass the JSON to a fresh RestoreFromJson(string, RecoveryMode, ResolutionPolicy).
public class ReplaySave
Inheritance System.Object → ReplaySave
Example
// 1. Make a choice to mutate state, then serialize to JSON.
runtime.SelectChoice("node_greet");
string json = runtime.SaveToJson();
// 2. Restore on the same runtime (simulating a reload from disk).
// RecoveryMode.BestEffort (the default) skips unresolvable commits
// so the session survives project drift.
// ResolutionPolicy.Lenient (the other restore-decision axis, also
// the default) accepts uuid-to-id fallback when nodes were re-exported.
ReplayDiagnostics diag = runtime.RestoreFromJson(
json,
recoveryMode: RecoveryMode.BestEffort,
resolutionPolicy: ResolutionPolicy.Lenient);
// 3. Inspect the outcome. CommitsApplied == TotalCommits is a clean restore.
bool cleanRestore = diag.CommitsApplied == diag.TotalCommits
&& diag.Warnings.Count == 0;
Remarks
The format is intentionally lean: rather than serializing the full variable and scene-stack state, it records the initial conditions (RandomSeed, InitialVarState, StartSceneId) and the ordered sequence of player actions (Path). Restore works by re-running those actions from scratch, which guarantees that the restored runtime is in exactly the same state as the saved one.
Properties
InitialVarState
Variable snapshot captured before the first player action — overrides for variables that were set programmatically before SelectChoice(string) was first called. Applied at restore time before replay begins.
public Dictionary<string,object> InitialVarState { get; }
Property Value
System.Collections.Generic.Dictionary<System.String,System.Object>
Path
Ordered list of replay commits. Each inner list is one “commit” — a batch of ReplayPathEntry items that were applied together in a single player action (typically one SelectChoice(string) call). Replay re-applies the commits in order via the same runtime APIs used at record time.
public List<List<ReplayPathEntry>> Path { get; }
Property Value
System.Collections.Generic.List<System.Collections.Generic.List<ReplayPathEntry>>
ProjectVersion
Version string from the bonsai project at save time — used during restore to detect project version drift (the same project may have been updated between save and restore). Null when the project carries no version.
public string? ProjectVersion { get; }
Property Value
RandomSeed
RNG seed captured at session start. Replayed exactly so any random expressions (dice rolls, random skill check modifiers) produce the same outcome on restore.
public int RandomSeed { get; }
Property Value
SchemaVersion
Save-format version. Current value is "1.0.0". Checked at restore time to detect incompatible schema changes.
public string SchemaVersion { get; }
Property Value
StartSceneId
Id or uuid of the scene where the session began. Passed to StartProject(string, SceneScope) at the start of replay to land the runtime in the correct initial scene before the first commit in Path is applied.
public string StartSceneId { get; }
Property Value
ValidatedWrites
Records the post-validator resolved value for each write that passed through
an OnBeforeVariable callback during the original session. Re-applied
during restore so validated side-effects (e.g. clamped meters) produce the
same results even when the host’s validator logic has changed.
Contains ValidatedWriteEntry items keyed by commit index and variable key.
public List<ValidatedWriteEntry> ValidatedWrites { get; }