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:
- The GameData box to save into.
- A key (a string label) so you can identify the data later.
- 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:
- Call
LoadFromDiskto read the file into memory. - 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:
- Setup: Creating GameData and configuring it in the
Start()method. - Saving: Using
SaveSystem.Set()to save multiple data types andSaveToDisk()to persist them. - Loading: Checking if a file exists, loading it, and safely retrieving values with
HasKey()beforeGet<T>(). - Type Safety: Each value is saved and retrieved with its proper type
(
<string>,<int>,<Vector3>).
6. Tips for Beginners
- Use unique keys: keys are case-sensitive! "score" and "Score" are different. you can also save the keys as a const variable to avoid typos.
- Check if data exists: Use
SaveSystem.HasKey(data, "Key")afterLoadFromDiskto confirm the value is available before you try to get the code. - Avoid null values:
SaveSystem.Setskips nulls, unsupported types, and logs a warning, so ensure you pass actual data. - Save frequently: Call
SaveToDiskat checkpoints or when exiting the game. - Missing data: If you request a key that doesn't exist, you'll get a default value (0 for numbers, null for objects).
