JSON file saving and loading system with unity to save and load generic types. Supports multiple save slots and profiles.
- newtonsoft.json (any version)
- Create a custom save profile data object to save custom data:
using SaveLoad;
[System.Serializable]
public record MySaveData : SaveProfileData
{
public Vector3 position;
public int currentLevel;
public float health;
public float xp;
}
- Save values to the save profile data object:
var saveData = new MySaveData
{
position = transform.position,
}
//OR
var saveData = new MySaveData();
saveData.position = transform.position;
- Save the data:
saveData.SaveAs(
/*save name*/ "mySave",
/*overrite existing save with same name?*/ false);
The repo also contains a sample save profile inside Saves
using SaveLoad;
Saves.playerSaveData.position = transform.position;
Saves.playerSaveData.SaveAs("playerData", "false");