# New Save & Load System

The Save & Load System allows you to save and load various elements of your scene, such as position, rotation, items, armor, objects that were destroyed, etc.

In the folder below you will find a demonstration of the save & load system.

<figure><img src="/files/822xR9oSVs7i4Ces9fS8" alt=""><figcaption></figcaption></figure>

Add the components below to save and load the respective data:

| Script Name               | Description                                                |
| ------------------------- | ---------------------------------------------------------- |
| JUAutoSave                | Automatically saves the game state at defined intervals.   |
| JUSaveLoadArmor           | Handles saving and loading of character armor data.        |
| JUSaveLoadCharacter       | Saves and loads general character properties and stats.    |
| JUSaveLoadComponent       | Base class for create scripts with save/load capabilities. |
| JUSaveLoadDestroyedObject | Tracks and restores destroyed objects in the scene.        |
| JUSaveLoadGeneralItem     | Manages saving and loading for generic inventory items.    |
| JUSaveLoadHealth          | Handles saving and restoring health values.                |
| JUSaveLoadInventorySlotUI | Saves and restores inventory slot UI state.                |
| JUSaveLoadItem            | Base class for saving and loading individual items.        |
| JUSaveLoadMeleeWeapon     | Saves and loads data for melee weapons.                    |
| JUSaveLoadManager         | Central manager that coordinates all save/load processes.  |
| JUSaveLoadModeComponent   | Allows different save/load modes (Global, Scene)           |
| JUSaveLoadThrowableItem   | Manages saving and loading for throwable inventory items.  |
| JUSaveLoadWeapon          | Saves and loads ranged weapon data.                        |
| JUSaveLoadWheeledVehicle  | Manages saving and loading of wheeled vehicle states.      |
| JUSavePointTrigger        | Trigger that initiates a save at specific points.          |

### Custom Save and Load Data

In some situations, you may want to save additional data beyond the default JU TPS data, such as the player's level, custom progress variables, or specific gameplay states.\
Below is a detailed example showing how to create a custom script to save, load, and delete this type of data using the **JU.SaveLoad** library.

{% code title="PlayerCustomSaveExample.cs" overflow="wrap" fullWidth="false" %}

```csharp
using UnityEngine;
using JU.SaveLoad; // Use JU.SaveLoad library

public class PlayerCustomSaveExample : MonoBehaviour
{
    // Example data to save
    public int playerLevel = 1;
    public float playerHealth = 100f;
    public Vector3 playerPosition;

    private string sceneName => UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;

    // Keys to load and save data
    private const string LevelKey = "playerLevel";
    private const string HealthKey = "playerHealth";
    private const string PositionKey = "playerPosition";

    void Start()
    {
        // Example: Try to load the data when the scene starts
        LoadPlayerData();
    }

    public void SavePlayerData()
    {
        // Save primitive types (int, float, string, bool, etc)
        JUSaveLoad.SetSceneValue(sceneName, LevelKey, playerLevel);
        JUSaveLoad.SetSceneValue(sceneName, HealthKey, playerHealth);

        // Save complex types like Vector3 (because JUSaveLoad has custom JsonConverters for Vector types)
        JUSaveLoad.SetSceneValue(sceneName, PositionKey, playerPosition);

        // Apply the save (don't forget this!)
        JUSaveLoad.Save();

        Debug.Log("Player data saved successfully.");
    }

    public void LoadPlayerData()
    {
        // Load player level (with default value if not found)
        playerLevel = JUSaveLoad.GetSceneValue(sceneName, LevelKey, 1);

        // Load player health
        playerHealth = JUSaveLoad.GetSceneValue(sceneName, HealthKey, 100f);

        // Load player position
        playerPosition = JUSaveLoad.GetSceneValue(sceneName, PositionKey, Vector3.zero);

        // Apply position to player
        transform.position = playerPosition;

        Debug.Log("Player data loaded successfully.");
    }

    public void DeletePlayerData()
    {
        // Optional: Delete specific saved keys
        JUSaveLoad.DeleteSceneValue(sceneName, LevelKey);
        JUSaveLoad.DeleteSceneValue(sceneName, HealthKey);
        JUSaveLoad.DeleteSceneValue(sceneName, PositionKey);

        // Apply the deletion
        JUSaveLoad.Save();

        Debug.Log("Player save data deleted.");
    }
}

```

{% endcode %}


---

# Agent Instructions: 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:

```
GET https://julhiecio.gitbook.io/ju-tps-documentation/game-development/new-save-and-load-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
