# Example Script

This script saves the player's transform values when the game is exited and loads the transform values on start.

{% hint style="info" %}
When saving a transform with ESave, only the position, rotation, and scale properties are saved.
{% endhint %}

```csharp
using UnityEngine;
using Esper.ESave;

public class SaveLoadExample : MonoBehaviour
{
    // Const data ID
    private const string playerTransformDataKey = "PlayerTransform";

    [SerializeField]
    private Transform playerTransform;

    private SaveFileSetup saveFileSetup;
    private SaveFile saveFile;

    private void Start()
    {
        // Get save file component attached to this object
        saveFileSetup = GetComponent<SaveFileSetup>();
        saveFile = saveFileSetup.GetSaveFile();

        // Load game
        LoadGame();
    }

    /// <summary>
    /// Loads the game.
    /// </summary>
    public void LoadGame()
    {
        // Check if the data exists in the file
        if (saveFile.HasData(playerPositionDataKey))
        {
            // Get Vector3 from a special method because Vector3 is not savable data
            var savableTransform = saveFile.GetTransform(playerPositionDataKey);
            playerTransform.CopyTransformValues(savableTransform);
        }

        Debug.Log("Loaded game.");
    }

    /// <summary>
    /// Saves the game.
    /// </summary>
    public void SaveGame()
    {
        saveFile.AddOrUpdateData(playerPositionDataKey, playerTransform);
        saveFile.Save();

        Debug.Log("Saved game.");
    }
    
    private void OnApplicationQuit()
    {
        SaveGame();
    }
}
```


---

# 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://espergames.gitbook.io/esave/scripting/saving-and-loading/example-script.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.
