Persistence and Serialisation

There's a lot of use to learning about serialisation and persistence in games. After all, most, if not all contemporary games have a need for persistence, be it saving the game's progress, saving the player's setting preferences or carrying weapons or choices from level to level, you know, having data that will persist in and outside of the game.

Here is a small Unity project I made which demos saving and loading in Unity. The only things being saved and loaded are integers and they're going out into a binary file. Of course saving only integers is relatively simple. However, now that I know how to save out simple data, I can slowly move on to more complex data. This system also only saves out to a binary file, though I feel that knowing how to save out into a .json, or .xml will be just as useful, as each file type can be used for various things.

For example, Json and XML are much more human readable and easily editable, while they might allow for weaknesses in the program that can be exploited, they can also allow easy editing of data without ever touching the Unity editor. One use we were able to come up with, for example, was for the project that I'm working on right now, which contained a lot of written dialogue. An idea that my group and I had was to have a json database that programmers could load and assign elements of to objects via scripts, allowing the person editing the dialogue to easily change it without touching the code. This worked somewhat, though this element was quickly dropped to save time. The downside to these files is that they're rather slow to read and write, which is why they should be used for storing data that is used for initialisation.

Binary files are less human readable and are harder to edit, and so is much better for holding data that shouldn't be touched by the casual player. Reading and writing binary is much faster than reading and writing json or xml, and so it's more useful for doing things like autosaving, quicksaving or quickloading. They're also much smaller, though now that games are almost in the hundreds of gigabytes per game, I doubt it really matters, though every little bit counts. In the end, I'm sure I'll end up knowing how to do both in the various languages I'm sure to know... eventually.

 

Tylah Kapa