FieldSaveLoadManager

Overview

Saves/loads fields explicitly marked with [SaveField] on components that live under a Saveable root. Supports primitives, enums, common Unity structs (Vector2/3/4, Quaternion, Color), and UnityEngine.Object references to other saveable scene objects (including inactive).

Disk File

  • fields.json in Application.persistentDataPath.

How It Works

  • Walks all Saveable objects in the current scene (including inactive) and inspects each MonoBehaviour for fields with [SaveField] (honors inheritance).
  • Serializes each field to a record containing:
    • saveableGuid (the root Saveable’s GUID),
    • component type and index on the GameObject,
    • field name,
    • either a typed payload (for non-Unity refs) or a UnityRef (for scene refs/assets).
  • Unity refs to scene objects are resolved back through the Saveable GUID + component index on load.
  • Uses an atomic write strategy (.tmp → replace) to avoid corrupted save files.

Public API

  • void Register(Saveable s), void Unregister(Saveable s) — optional runtime registry.
  • void SaveAll() — discovers and writes all marked fields.
  • void LoadAll() — reads and applies saved field values to matching components/fields (best-effort with logging).

Data Format

  • JSON payload version 2.
  • Primitive and numeric types are culture-invariant.
  • Unity structs and POCOs are serialized via JsonUtility.

Editor / Inspector

A custom inspector exposes Save Fields Now and Load Fields Now.