Tutorial Contents

Beginner's Guide to the Lix Save System

Welcome! This guide will teach you how to save and load game data using the Lix Save System even if you're new to programming.


1. Setting Up

First, create an instance of the GameData object. Think of it as a "box" or "save slot" where you store everything you want to save for example, the player's name or score.

using SillyLixStudio.SaveSystem;

// Create the save container (GameData)
GameData mySaveData = new GameData();

// Recommended settings to change right away:

// 1. Set a custom file name (e.g., "SaveSlot1")
mySaveData.gameDataConf.SetFileName("SaveSlot1");

// 2. Enable or turn off encryption (optional, but keeps data safe)
mySaveData.gameDataConf.SetIsEncrypted(true);

// 3. Set your secret keys (make these unique to your game! or even better, generate them dynamically)
mySaveData.gameDataConf.SetEncryptionKey("my-super-secret-key-12345");
mySaveData.gameDataConf.SetEncryptionIV("my-initialization-vector-567");

Supported Types: You can save all primitive types, string, decimal, and Unity's Vector2, Vector3, Vector4, and Quaternion.

Tip: If you plan to implement your own storage, serialization, or encryption classes, also import using SillyLixStudio.SaveSystem.Interfaces;.

Check the full documentation to learn more about these settings.


2. Saving Your First Data

To save data, use SaveSystem.Set. You need three things:

  1. The GameData box to save into.
  2. A key (a string label) so you can identify the data later.
  3. The value you want to save.

Then call SaveSystem.SaveToDisk to write everything to a file.

// Step 1: Put data into the box
SaveSystem.Set(mySaveData, "Score", 500);
SaveSystem.Set(mySaveData, "PlayerName", "Hero");
SaveSystem.Set(mySaveData, "LevelCompleted", true);

// Step 2: Write the box to the hard drive
// IMPORTANT: If you forget this, data is lost when the game closes!
SaveSystem.SaveToDisk(mySaveData);

3. Loading Data

To get your data back, follow these steps:

  1. Call LoadFromDisk to read the file into memory.
  2. Use Get<Type> to retrieve specific values.
// Step 1: Load the file from disk into your GameData object
SaveSystem.LoadFromDisk(mySaveData);

// Step 2: Retrieve values using the same keys you saved with
//  tells the system you expect a number
int loadedScore = SaveSystem.Get<int>(mySaveData, "Score");

//  tells the system you expect text
string loadedName = SaveSystem.Get<string>(mySaveData, "PlayerName");

// Print results to Console
Debug.Log("Score: " + loadedScore);
Debug.Log("Name: " + loadedName);

Congratulations! You've successfully saved and loaded data using the Lix Save System.


4. Complete Example

Here's a complete, ready-to-use example that combines everything into a single script:

using UnityEngine;
using SillyLixStudio.SaveSystem;

public class SaveSystemExample : MonoBehaviour
{
    private GameData mySaveData;

    private void Start()
    {
        // 1. Create GameData instance
        mySaveData = new GameData();
        mySaveData.gameDataConf.SetFileName("PlayerSave1");
        mySaveData.gameDataConf.SetIsEncrypted(true);
        mySaveData.gameDataConf.SetEncryptionKey("unique-key-12345");
        mySaveData.gameDataConf.SetEncryptionIV("unique-iv-67890");
    }

    void SaveData()
    {
        // 2. Save some data
        SaveSystem.Set(mySaveData, "PlayerName", "Hero");
        SaveSystem.Set(mySaveData, "HighScore", 1500);
        SaveSystem.Set(mySaveData, "PlayerPosition", new Vector3(10f, 0f, 5f));

        // 3. Write to disk
        SaveSystem.SaveToDisk(mySaveData);
    }

    void Load()
    {
        // 4. Load from disk
        if (SaveSystem.SaveFileExists(mySaveData))
        {
            SaveSystem.LoadFromDisk(mySaveData);

            // 5. Retrieve data
            // check if keys exist before getting
            if (SaveSystem.HasKey(mySaveData, "PlayerName"))
            {
                // get values
                string playerName = SaveSystem.Get(mySaveData, "PlayerName");
            }
            if (SaveSystem.HasKey(mySaveData, "HighScore"))
            {
                int highScore = SaveSystem.Get(mySaveData, "HighScore");
            }
            if (SaveSystem.HasKey(mySaveData, "PlayerPosition"))
            {
                Vector3 playerPosition = SaveSystem.Get(mySaveData, "PlayerPosition");
            }

            Debug.Log($"Player Name: {playerName}, High Score: {highScore}, Position: {playerPosition}");
        }
        else
        {
            Debug.Log("No save file found.");
        }
    }
}

This example shows:


6. Tips for Beginners

Back to Full Documentation