Worlds, saving and loading
A .matterworld document contains cells, tick, grid layout, solver settings,
world mapping, ordered substance-schema identity, metadata and a checksum. It
does not contain GameObjects, renderer settings, lights, physics bodies or
network connections. Save those separately in the application's scene/save system.
Paint, save, assign, Play
- Import Basic Setup through Tools > Matter > Samples and open its scene.
- Select the
MatterSimManagerto open the World Editor in Scene View. - Paint the world and choose Save As under Matter World Settings.
- Save a
.matterworldfile belowAssets; Unity imports aMatterWorldAsset. - Select the sample bootstrap. Choose Saved World and assign that asset.
- Enter Play Mode and verify the saved cells and mapping.
Generated Basin remains Basic Setup's default. A missing or incompatible Saved World reports an error; it never silently substitutes the generated basin. See Editor tools for preview, Undo and recovery behavior.
Load a world in your own scene
Quick Setup connects the simulation and renderers for a blank world. It does not add a startup loader or automatically assign the World Editor's current document for Play Mode.
- Save your Unity scene and save the authored cells as a
.matterworldbelowAssets. These are separate files. - Give your startup script references to the scene's
MatterSimManagerand the importedMatterWorldAsset. - Assign the matching substance database, keep automatic ticking and gameplay edits paused, and initialize the manager.
- Call
Deserialize()on the asset and awaitMatterWorldPersistence.ApplyAsyncwith substance-schema validation enabled. This works with native compute, CPU, and WebGPU. - Start automatic ticking and gameplay only after the load completes successfully.
The portable byte-save helper below is another option:
pass asset.CopySerializedBytes() to MatterSaveExample.RestoreAsync for an
initialized manager. The helper restores the manager's prior automatic-tick
state, so a manager paused during startup stays paused until your code starts it.
Opening a document in the World Editor changes the authoring session; it does not add this startup logic to a scene. Basic Setup's Saved World bootstrap provides a ready-made example of that logic.
Choose the appropriate API
| Task | Entry point |
|---|---|
| Capture cells and metadata | MatterWorldPersistence.CaptureAsync |
| Produce portable bytes | SaveToBytesAsync |
| Save a native filesystem document | SaveToFileAsync |
| Read and validate a native file | LoadFromFileAsync |
| Apply an already read document | ApplyAsync |
| Read an imported asset | MatterWorldAsset.Deserialize |
| Validate bytes without an exception-based result | MatterWorldSerializer.TryDeserialize |
CPU and native compute support synchronous equivalents. Prefer asynchronous
capture/application in portable integrations: WebGPU cannot perform synchronous
GPU readback. MatterWorldAsset.LoadInto is synchronous; for WebGPU deserialize
the asset and pass the result to ApplyAsync.
Call simulation and Unity-object APIs from Unity's main thread. Await operations
normally rather than using .Wait() or .Result. Serialize gameplay mutations
around a load: pause automatic ticking, block competing edits/backend switches,
and restore the application's prior running state in finally.
Portable byte saves
The following complete helper works with an initialized manager and delegates byte storage to the application. Call it from an awaited gameplay operation; handle cancellation, I/O and validation errors at that application's boundary.
using System;
using System.Threading;
using System.Threading.Tasks;
using MasterTech.Matter.Serialization;
using MasterTech.Matter.Simulation;
public static class MatterSaveExample
{
public static async Task<byte[]> CaptureAsync(
MatterSimManager simulation, CancellationToken cancellationToken)
{
if (simulation == null) throw new ArgumentNullException(nameof(simulation));
bool wasRunning = simulation.SimulateAutomatically;
simulation.SimulateAutomatically = false;
try
{
return await MatterWorldPersistence.SaveToBytesAsync(
simulation, cancellationToken: cancellationToken);
}
finally
{
if (simulation != null) simulation.SimulateAutomatically = wasRunning;
}
}
public static async Task RestoreAsync(
MatterSimManager simulation, byte[] bytes, CancellationToken cancellationToken)
{
if (simulation == null) throw new ArgumentNullException(nameof(simulation));
if (bytes == null) throw new ArgumentNullException(nameof(bytes));
MatterWorldSave world = MatterWorldSerializer.Deserialize(bytes);
bool wasRunning = simulation.SimulateAutomatically;
simulation.SimulateAutomatically = false;
try
{
await MatterWorldPersistence.ApplyAsync(simulation, world,
new MatterWorldLoadOptions { ValidateSubstanceSchema = true },
cancellationToken);
}
finally
{
if (simulation != null) simulation.SimulateAutomatically = wasRunning;
}
}
}
The helper does not drain queued edits or stop other scripts from modifying the world. The application must coordinate those systems before calling it. Cancellation is checked around readback and application; it does not guarantee that an already submitted GPU operation or filesystem write can be interrupted.
Loading policy and failures
MatterWorldLoadOptions defaults all four policies to true:
- ReconfigureSimulation: permit allocating the saved layout when needed.
- ApplySimulationSettings: restore saved solver/cadence settings.
- ApplyWorldMapping: restore origin and cell size.
- ValidateSubstanceSchema: require the target database's ordered identity to match the saved document.
Disabling reconfiguration rejects an incompatible layout. Disabling schema validation is not a material remapper: only use it inside a deliberate migration that controls every ID. Append substances carefully and test compatibility; unchanged numeric IDs alone do not establish matching saved-schema identity.
Deserialization validates format, lengths, encoding and checksum. Capture requires an initialized manager. Application validates the target database and captures rollback state when a world is already initialized. A failed application attempts to restore that state; if rollback also fails, the exception includes both failures. Report the error and stop relying on that manager until repaired. Do not report a successful save or load until its awaited operation completes.
Native file saving uses an atomic replacement path. Browser persistence requires an application storage layer; the Showcase synchronizes its virtual filesystem to IndexedDB. See Web deployment.
Recovery and backups
The World Editor's recovery snapshots protect authoring work, not the player's save directory. Its recovery banner, source conflict handling, Retry Recovery, and preview acceptance rules are described in Recovery and file conflicts.
Keep backups of your original worlds and preserve the database's substance order. Validate saved worlds before applying them to a running simulation.