Basic Practices for Saving in Unity

I know most people use PlayerPrefs, but what is the best practice to follow for saving? Should each game object have a save and load function thats called on entering and exiting? Or is there a better way to do this?

PlayerPrefs are for saving preferences mostly (hence the name, and the limited data types it works with), so I doubt that’s what most people use for saving games. As a start, look into serialization.

–Eric

It depends on how complex your saving/loading is. Serialization or assets (in the store, I mean) are your best choices for more complicated things. However, for simpler things, you can use PlayerPrefs.

At the moment - after my “massive” ordeal figuring out PlayerPrefs, ScriptableObjects and Unity’s built-in serialization - I’m using both ScriptableObjects/built-in Serialization and PlayerPrefs… although I may not be using it the same way as everybody else. The ScriptableObjects simply hold data of each level (id, name, number of items in level, this or that that are constant and vary between levels) and the PlayerPrefs hold simple but variable data between levels (high scores, top time, unlocked, etc).

Edit: Here ya go:
http://forum.unity3d.com/threads/222602-Best-way-to-save-and-load-data-(simpler-medium-complexity)
Guess it helps to save these old threads :smile:

My first thought was to serialize my objects into JSON strings and save it into PlayerPrefs, but wasn’t sure if that is a good idea.

If you’re going to serialize them you might as well just write to disk/device. You can use the Application.PersistentDataPath property to get the save path and write the file there.

Does anyone know of any libraries that can serialize objects into JSON using reflection rather than attributes/annotations? Basically, I want to be lazy.

Yeah sure… My asset does but it’s not free:

JSON .NET for Unity