Scripting API
Scripting API
WorldSnapshot
Class in Abyss.Core, from Abyss.Core.
What a world's entities held at one moment, to be put back onto the same entities.
public sealed class WorldSnapshot : IDisposableRemarks
Onto the same entities, rather than a scene saved and loaded again: an entity's id is what a selection, a hierarchy's folds and an undo history refer to, and each would be lost to a reload. What a game changes while it plays is put back at Stop, and the entities afterwards are the entities from before.
Every value that can be copied is kept: through Bevy's reflection for Bevy's components and a plugin's, and as bytes for the ones declared from C#. What cannot be is named in WorldSnapshot.Unkept. Putting it back despawns whatever appeared since, gives back whatever went — under a new id, which SnapshotRestore.Respawned reports — and rebuilds the hierarchy in its old order if anything in it moved. See abyss_core::snapshot.
And the game's resources — a score, a level — the same way: what the game changed is written back, what it made is taken away, and what it took away is given back. Only the game's; see WorldSnapshot.Resources.
Properties
Entities
public int Entities { get; }How many entities it holds.
Resources
public int Resources { get; }How many of the game's resources it holds the values of: every resource declared from C#, and a Rust one whose type comes from a crate that names one of the game's plugins. The engine's and Bevy's are left as they are. See abyss_core::snapshot, A game's resources.
Unkept
public IReadOnlyList<string> Unkept { get; }The components on its entities whose values it could not keep, by name, once each: a value that owns something and cannot be reflected. Putting it back leaves what they hold alone.
Methods
Restore
public SnapshotRestore Restore()Puts every entity back as it was; see the class remarks. May be done more than once.
Exceptions
ObjectDisposedException: It, or its world, has been disposed.
Changed
public string? Changed()The first thing the world holds otherwise than this kept it, in a few words — "Transform on 5v1" — or null where it holds the same: the same entities, each with the same components and values, in the same hierarchy in the same order, and the game's resources the same. What an editor asks after a command it ran, to tell whether it changed anything.
Exceptions
ObjectDisposedException: It, or its world, has been disposed.
Values compared as Bevy's reflection compares them, a C# component's by its bytes; what it could not keep (WorldSnapshot.Unkept) is not asked about. About as long as taking it.
Dispose
public void Dispose()