# Save/Load System — MVP Implementation Roadmap (Unity2D) ## Overview A minimal, deterministic save/load system built for Unity2D projects with a guaranteed bootstrap initialization sequence and a central scene management service. The system focuses on consistency, low coupling, and predictable behavior without unnecessary abstractions or runtime complexity. --- ## Core Concepts ### Central Manager A single SaveLoadManager instance, initialized through the bootstrap system before any gameplay scene is loaded. This manager persists across scenes and is responsible for orchestrating save and load operations, participant registration, and serialized data handling. ### Participants GameObjects that hold gameplay-relevant state implement a lightweight interface providing unique identification and serialization methods. They can be either static (pre-authored scene objects) or dynamic (runtime-spawned). ### Scene Integration The save/load system integrates tightly with the scene management service, subscribing to scene load and unload callbacks. On scene load, the manager performs full discovery of eligible participants and restores state. On scene unload, it unregisters relevant objects to maintain a clean registry. --- ## System Responsibilities ### SaveLoadManager - Maintain a persistent data structure representing the full save state. - Manage participant registration and lookup via a unique identifier system. - Handle scene lifecycle events to trigger discovery and cleanup. - Coordinate save and load operations, converting participant data to and from serialized storage. - Expose methods for manual saving and loading, typically called by gameplay or UI logic. ### ISaveParticipant Interface Defines the minimal contract required for an object to be considered saveable. Each participant must: - Provide a globally unique identifier. - Be able to capture its state into a serializable representation. - Be able to restore its state from that representation. ### SaveData Structure Acts as the top-level container for all serialized object states. Typically includes a dictionary mapping unique IDs to serialized object data, and may include versioning metadata to support backward compatibility. --- ## Lifecycle Flow 1. The bootstrap system initializes the SaveLoadManager and any required dependencies before gameplay scenes are loaded. 2. When a new scene loads, the manager is notified by the scene management service. 3. During the loading phase (preferably hidden behind a loading screen), the manager performs a full discovery pass to locate all saveable participants in the scene. 4. The manager retrieves corresponding saved data (if available) and restores state for each discovered participant. 5. During gameplay, any dynamically spawned object registers itself with the manager at creation and unregisters upon destruction. 6. When saving, the manager queries each registered participant for its current state, stores it in the data structure, and serializes the entire dataset to disk. 7. When a scene unloads, the manager automatically unregisters all participants from that scene to prevent stale references. --- ## Simplifications and Design Rationale - The manager’s existence is guaranteed before gameplay, eliminating initialization-order problems. - No deferred registration queue or reflection-based discovery is required; direct registration is deterministic. - Inactive GameObjects are ignored during discovery, as their inactive state implies no dynamic data needs saving. - Scene discovery occurs once per load cycle, minimizing runtime overhead. - The system remains centralized and data-driven, allowing for future extension (e.g., async saves, versioning, partial scene reloads) without refactoring core architecture. --- ## Recommended Integration Points - **Bootstrap System:** Responsible for initializing SaveLoadManager before gameplay scenes. - **Scene Management Service:** Provides lifecycle callbacks for scene load/unload events. - **Game State/UI:** Invokes manual Save() or Load() operations as part of gameplay flow or menu logic. - **Participants:** Register/unregister automatically in Awake/OnDestroy or equivalent initialization/destruction hooks. --- ## Expected Outcome The resulting implementation yields a predictable, low-maintenance save/load framework suitable for both small and large Unity2D projects. It avoids unnecessary runtime discovery, minimizes coupling, and ensures that saved data accurately reflects active game state across sessions.