I created a system which makes saving variables more convenient, with a custom save-file format

Hi All!

I created a system which makes saving variables more convenient, with a custom save-file format.

Initially, I was working on an idle-game template. I figured I needed a convenient way of saving (lots of) variables.

With that in mind, I created the .save file format. I’m sure it’s not the most unique file-structure, but it works AND it’s pretty small.

This system would allow the user to save/load any variable (supported types below) by simply adding the [Saveable] attribute. The system takes care of the rest.It can save/load public and private fields, without having to predefine all variables you want to add to the save file.

Current supported types:

bool
float
int
string
Vector3
Vector4

Let me know if you’re interested in such a system; With enough interest I’ll finish it asap and publish it :wink:

Attached is an image of the save-file and the usage.

There are already plenty of viable solutions built-in or available as add-ons.

  • PlayerPrefs
  • JsonUtility
  • ScriptableObjects (read-only at runtime but values could be saved as Json)

Rather than having a couple fields, instead I would make a struct or class with savable fields such that you can save them all at once and you don’t need any filtering attributes. Example code (incomplete):

public class MyClass : MonoBehaviour
{
    [Serializable]
    public struct Saveables
    {
        public int aValue;
        public float anotherValue;
        public string someText;
        public bool thatFlag;
        public Vector3 thePosition;
        public Quaternion theRotation;
        public Color32 myColor;
        public byte[] gridCoords;
       // etc etc
    }
 
    private Saveables _saveables = new();
 
    private void OnDestroy()
    {
        File.WriteAllText(path, JsonUtility.ToJson(_saveables));
    }
}

This supports all Serializable types, including nested types and their fields.