Persistence
StellarWorks.Persistence.ModPersistence exposes the data owned by one mod namespace. Access it on the game thread.
| Member | Scope |
|---|---|
Global | Local installation. Writes commit immediately to StellarWorks/global.db under the game's persistent data path. |
World | Active authoritative world. Changes commit with the next native save. |
ForShip(Guid), ForPart(Guid), ForPlayer(Guid) | Data tied to a persistent entity in the active authoritative world. |
ForPart(PartContext) | Uses the persistent ID of a placed custom part. |
CreateEntity(kind), ForEntity(Guid) | Creates and uses custom persistent entities owned by your mod. |
Entities(EntityKind) | Lists known entities of that kind, scoped to your mod for custom entities. |
Use WorldId and IsWorldAuthority to check context. World scope handles belong to the session where you acquired them.
Read and write keys
IModData supports Get<T>(key, defaultValue), Contains(key), Set<T>(key, value), Remove(key), and Keys(). Values are serialised as JSON. IModStorage.Batch(Action<IModData>) atomically applies a batch within one scope when the callback returns successfully. Use the batch handle only inside that callback.
Version stored data
The schema starts at version 1. DefineSchema(version) sets the desired version. Use RegisterMigration(fromVersion, action) to supply the step from an existing version to the next. Register these during initialisation. StorageMigration.Scopes enumerates scopes with stored values for the mod, and StorageMigration.For(scope, entity) opens an edit within the migration. Check IsGlobal before selecting a database-specific scope. Supply the entity GUID for entity scopes.
World persistence keeps the native save and its SQLite database together. Storage examples and recovery procedure