> For the complete documentation index, see [llms.txt](https://apex-studio.gitbook.io/apex-secure-vault-official-documentation./llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apex-studio.gitbook.io/apex-secure-vault-official-documentation./core-concepts-saving-data.md).

# Core Concepts Saving Data

Saving data with Apex Secure Vault requires zero manual JSON parsing, binary formatting, or file writing. We utilize a modern, Attribute-based architecture to make saving as simple as adding a single line of code.

#### Step 3.1: The SaveableObject Base Class

To make any script capable of interacting with the vault, change its inheritance from the standard MonoBehaviour to SaveableObject. This automatically registers and unregisters the object from the SaveStateRegistry during OnEnable and OnDisable.

```csharp
using UnityEngine;
using ApexStudio.ApexSecureVault;

public class PlayerStats : SaveableObject 
{
    // Your game logic goes here...
}
```

#### Step 3.2: Generating a Unique Vault ID

Once your script inherits from `SaveableObject`, select the GameObject containing this script in the Unity Hierarchy. You will notice a newly injected custom UI inside the Inspector titled "Apex Secure Vault Identity".

1\.  Look for the blue "Generate ID" button.

2\.  Click it to generate a unique GUID (Globally Unique Identifier).

3\.  This ID securely binds this specific GameObject's data to the encrypted save file, ensuring data is accurately restored to the correct object even if scenes change.

<figure><img src="/files/bvsv04t0SVYTXSTtau1U" alt=""><figcaption></figcaption></figure>

#### Step 3.3: The \[SaveState] Attribute

Now that your object is registered, you must explicitly tell the engine *which* variables you want to save. Add the \[SaveState] attribute above any Field or Property. The system will automatically scan, serialize, encrypt, and store these marked variables.

```csharp
using UnityEngine;
using ApexStudio.ApexSecureVault;

public class PlayerStats : SaveableObject 
{
    [Header("Player Data")]
    
    [SaveState] // This public variable will be saved and encrypted!
    public int playerLevel = 1;

    [SaveState] // It works perfectly on private variables too!
    [SerializeField] private string playerName = "ApexStudio";

    [SaveState("SecretCoinsKey")] // You can optionally define a custom string key for the vault
    public int coinsAmount = 0;

    // This variable lacks the attribute, so it will NOT be saved (Temporary Data)
    public float currentHealth = 100f; 
}

```

**Developer Note:** Supported data types for the \[SaveState] attribute include all standard C# primitive types (int, float, string, bool, etc.), Unity structs (Vector3, Quaternion, Color, etc.), and our custom Anti-Cheat types which will be discussed in the next section.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://apex-studio.gitbook.io/apex-secure-vault-official-documentation./core-concepts-saving-data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
