Null Bolt
Studio
guides

Saving generated items

Don't serialize the item — serialize the recipe. A snapshot is six plain fields that regenerate the identical item on load.

Why not just JSON the ItemInstance?

Because it holds live asset references — Rarity, ItemType, Icon, Prefab, the source affixes. JsonUtility can't round-trip those; you'd get hollow items on load. Determinism gives you a better deal: since the same seed always rolls the same item, you only need to store the seed and the names of the definitions involved.

Capture & restore

Persistence in practice
C#
using ItemGeneratorSystem;
using UnityEngine;

// SAVE — six plain fields, safe for JsonUtility / Newtonsoft / PlayerPrefs
ItemInstanceSnapshot snap = ItemInstancePersistence.Capture(item);
string json = JsonUtility.ToJson(snap);

// LOAD — resolve names through GeneratorSettings, re-roll from the seed
var restored = ItemInstancePersistence.Restore(
    JsonUtility.FromJson<ItemInstanceSnapshot>(json), settings);

if (restored == null) { /* a definition was renamed or missing — handle it */ }
Snapshot fieldTypeDescription
SeedintThe generation seed — the whole item in one number.
GeneratorVersionintVersion stamp; Restore warns when it differs from the current generator.
TemplateName / ItemTypeName / SubTypeName / RarityNamestringDefinition asset names, resolved through GeneratorSettings on restore.

The contract you're signing

RuleDescription
Registry must be populatedRestore resolves names via GeneratorSettings — run Auto-Discover Content after adding definitions, or restored items come back null.
Don’t rename shipped definitionsResolution is by asset name. Renaming Rarity_Epic after players have saves breaks their snapshots. Add new assets instead of renaming old ones.
Version drift warns, not breaksA snapshot from an older generator version restores best-effort with a console warning — the item may roll differently. Decide whether to migrate or accept.
Callbacks re-run on restoreOnPostGenerate fires during Restore too. Keep handlers deterministic or your restored items won’t match what was saved.
// tip
Snapshot JSON is plain ints and strings, so it nests cleanly inside any save system — including our SaveSystem asset and the Grid Inventory System's per-item customName/metadata, if you're running both.

Design-time assets instead

The editor window's GENERATE button takes the other path: it writes ItemDefinition ScriptableObjects (default folder Assets/GeneratedItems/, name format {Name}_{Rarity}_{Seed}). Those are permanent project assets — hand-pick the great rolls, ship them as quest rewards, or feed them to the Grid Inventory System's import bridge. Their inspector renders the full item card plus a read-only metadata foldout (seed, version, timestamp, source template).