What defineSave takes for a save that keeps one record for each
entity of the world holding each: a building’s blocks, a market’s
orders. The record keeps the trait’s own fields, each in the type its
default gives, or the narrower one the trait’s types names, as
Unreal’s save keeps every property not marked transient.
| Property |
Type |
Description |
each |
Each |
The trait whose holders the save keeps, one record each: every entity of the world holding it, but one a player’s record, a saved entity or a key keeps. |
exclude? |
readonly Excluded[] |
Fields the record does not keep, such as a cooldown: they come back as the entity’s spawn gave them. Excluding a field earlier versions kept is a removal, which raises the version. |
migrations? |
Readonly<Record<number, (saved) => unknown>> |
One step per version, run on each record’s fields as JSON, as the checkpoint codec writes them: a pure function from the old fields to the new. A field that holds an entity reaches it as the id of the record that keeps that entity. |
restorePose? |
"record" | "scene" |
Where a scene’s entity the save keeps stands as its record comes back. "record", the default, puts it at the pose its record kept, so a piece a player moved stays moved. "scene" leaves it where the scene places it now, so a fixed station the creator moves in a later version stands at its new place in every saved world. One save of an entity that says "scene" holds for the whole entity. An entity no scene places takes its record’s pose whatever this says. |
scopes |
readonly ["world"] |
A per-entity save is the world’s. |
version |
number |
Counts the changes to what a record keeps that its fields cannot read alone: a field removed, renamed or given another type. A field added to the trait needs no new version: a record stored before it leaves it as the entity’s spawn gave it. |
optional onEntityRestore(context): void
Runs once each record’s entity exists with its fields set: for
what the fields alone do not bring back, such as a stored piece’s
colliders turned to triggers. A throw refuses the world’s load.
void