Save System

A basic save system based on unity's JsonUtility

The save system is built on Unity's Json Utility which saves an object in a .json file. All the saves are located at Application.persistentDataPath which is located at C:\Users\<user>\AppData\LocalLow\<company name>on widows.

Methods

Name
Description

SaveObject

Saves the target object as a .json file in the designated save path.

LoadObject

Loads and deserializes the .json file with the specified name into the target generic type.

LoadAllObjects

Loads all .json files from the save path and deserializes them into the specified generic type.

DeleteFile

Deletes the .json file with the specified name from the save path.

DeleteAllFiles

Deletes all .json files in the save path, effectively clearing all saved data stored in that location.

Save

Saves a key with its value, similar to PlayerPrefs.SetKey(). This allows you to store data persistently between game sessions.

Load

Loads a key with its value, similar to PlayerPrefs.GetKey().

HasKey

Returns true if the Key list contains the specified key.

Example

To start using the save system, first add the FPSFramework namespace to the class you want to save and load from, like this:

using Akila.FPSFramework;

Now create a new class like this:

[System.Serializable]
public class Data
{
    public string name;
}

In Start(), call SaveSystem.Load(), and in OnApplicationQuit(), call SaveSystem.Save() inside the class you want to save and load from, like this:

public Data data = new Data();

private void Start()
{
    SaveSystem.Load<Data>("fileName");
}

private void OnApplicationQuit()
{
    SaveSystem.Save(data, "fileName");
}

Last updated

Was this helpful?