MOST Database
A lightweight, designer‑friendly save/state framework. You define named data entries (Int, Float, Bool, String) in one ScriptableObject; at runtime it seeds from your InitialValues on first launch, then auto‑loads/auto‑saves JSON under Application.persistentDataPath/MOST/. It includes range clamping, best‑score tracking, safe file writes, and simple lookup APIs.
Quick Start
Create: Right‑click → Create → MOST → Database → name it (e.g.,
M_Database).

Configure key (optional): In the inspector, set Database Key (used for save filename). Otherwise, the asset name is used.
Add Entries: Use the list to add
IntData,FloatData,BoolData, orStringData. Fill DataName and InitialValue; set Min/Max if needed.

Press Play: First run seeds from InitialValue and writes JSON. Future runs load from JSON automatically.

The Initialized flag in the inspector tells you whether a save exists and has been applied this session.
Concepts & Terminology
Entry / Data: A single variable (Int/Float/Bool/String) with a DataName and a unique generated ID.
InitialValue: Author‑time default; used only for seeding when there is no save file yet, or as baseline before applying saved values.
Value: Current runtime value (read‑only in inspector during play; modified by API).
HighestValue (Int/Float): Auto‑tracked peak (useful for best scores or max currencies).
EnableMin/Max: Optional clamping bounds; any Set/Add/Subtract passes through Clamp.
Database Key: A file key used to build a save file path (
MOST/<key>.json). Safe characters enforced.Context Menu: Delete Save File (This DB) removes the JSON for this database key (Editor‑only helper).
Persistence Lifecycle (no code needed)
On first Play: If no save exists, the DB seeds Value from InitialValue (and clamps), then saves JSON.
On subsequent Plays: The DB loads JSON, overlays values onto a fresh InitialValue baseline, and marks Initialized = true.
On Quit: Auto‑saves the latest values. Writes to a temporary
*.tmpthen atomically replaces the main file to avoid corruption.File Location:
{Application.persistentDataPath}/MOST/<DatabaseKey>.jsonMultiple Databases: Each asset gets its own file based on its key; all loaded DBs will be saved on quit.
API & Live Example?
Current Level: Start Level = 1 and Minimum ≥ 0 (No Level 0)
Score: Minimum> 0 (No negative score), and record the highest score
Currency: Init with 100 currency (Coins, Gems)
Bootstrap MonoBehaviour > inspector?

Get all the loaded Databases
Create a new data
Get the Data (entries) from the database
Important (Save/Load)
Use Save() after critical state changes (IAP unlocks, progression checkpoints) to guarantee persistence even if the app is killed.
Opreations
FAQ
Q: Do I need to manually load on start? A: No. The database auto‑initializes on play, loads if a file exists, otherwise seeds and saves.
Q: Can I have multiple databases? A: Yes—each gets its own JSON by key/asset name. All loaded DBs are saved on quit.
Q: What if I rename DataName after shipping? A: Saves are keyed by id, not by name. Renaming the display name is safe; removing or re‑ordering entries may affect semantics. Prefer adding new entries instead of recycling IDs.
Q: Is the file safe from corruption? A: Writes use a temporary file then File.Replace where available; this minimizes corruption risk.
Q: When is Initialized true?
A: After the DB loads from disk or writes a first save during the current play session.
Last updated