# Saving Component Data: Root-Level Prefabs vs. Individual Remember Components

Crystal Save uses a hybrid approach to saving data.\
The **root prefab’s Remember Prefab (SaveablePrefab)** manages **instance lifecycle and general hierarchy tracking**, while **component-specific Remember scripts** manage **custom field serialization** for individual components.

***

### 1. Is a Single ‘Remember’ Component on the Root Prefab Enough?

A single **SaveablePrefab** (Remember Prefab) on the root prefab **is sufficient** for:

* Creation and destruction tracking of prefab instances.
* Tracking changes to child objects’ **active state, tags, layers, runtime-added components, mesh/material changes, particle states, and Animator state** — if the relevant tracking toggles (`trackChildStateOverrides`, `trackComponentBlobs`, etc.) are enabled.

However, **component-specific data** — such as a child object’s **Health**, **Inventory**, **Transform**, or **custom script fields** — **still requires dedicated Remember components** (like `RememberTransform`, `RememberGameObject`, or custom `SaveableComponent` derivatives).

**Summary:**\
Root-level prefab management is covered, but component-specific data still needs its own Remember scripts or composites.

***

### 2. Must Every Additional Component Have a Custom ‘Remember’ Script?

Yes — **if you want to persist its state**. (Unless: Read above [#id-1.-is-a-single-remember-component-on-the-root-prefab-enough](#id-1.-is-a-single-remember-component-on-the-root-prefab-enough "mention"))

Crystal Save focuses on **fast load times** and **small save files**. To achieve this, it avoids costly reflection-based serialization where possible.\
Instead, each component is responsible for **pushing its state to the SaveManager** during save operations.

This means:

* **Any component whose internal state you want to persist needs a Remember script** (a `SaveableComponent` subclass).
* You must implement:
  * `SerializeComponentData()` – Convert your chosen fields into binary.
  * `DeserializeComponentData(byte[])` – Read from binary and reapply the values.

If you **don’t** add a Remember script, that component’s state **will not** be included in saves.

***

### Mermaid Diagram – Decision Flow

{% @mermaid/diagram content="graph TD
    A["Prefab to Save"] --> B{"SaveablePrefab on Root?"}
    B -- No --> C["Add SaveablePrefab to Root"]
    B -- Yes --> D{"Need to Save Component-Specific Data?"}
    D -- No --> E["Root SaveablePrefab is Enough"]
    D -- Yes --> F["Add Remember Component(s) to Target Components"]
    F --> G["Implement Serialize/Deserialize Methods"]
" %}

### Mermaid Diagram – Data Collection Flow

{% @mermaid/diagram content="graph TD
    subgraph "Save Process"
        A1["SaveManager"] --> B1["ComponentManager"]
        B1 --> C1["Registered SaveableComponents"]
        C1 --> D1["SerializeComponentData()"]
        D1 --> E1["SaveData.ComponentsData"]
    end
    
    subgraph "Load Process"
        A2["SaveManager"] --> B2["ComponentManager"]
        B2 --> C2["Find SaveableComponents by ID"]
        C2 --> D2["DeserializeComponentData()"]
        D2 --> E2["Apply State to Components"]
    end" %}
