October 08 2024
If you are a game developer using Unity, you will eventually want to release a solid game that performs and is stable (am I assuming too much?). Or maybe you even already have launched one or multiple “successful” games.
One key area you must consider here is serialization and deserialization. That is, the process of persisting gameplay state across gaming sessions or levels. All games do that, even these little arcade games from the eighties “modern” players barely play anymore.
Problem is: choosing the wrong serialization & deserialization technology inexperienced devs tell you about will only bring you pain.
Let me help you make a better decision.
Serialization is crucial for two main reasons:
Robustness: you don’t want to lose player progress or game state due to crashes or bugs. Additionally, you need to be able to update your game without breaking existing save games. There’s nothing like a furious player demanding a refund for your broken game because they lost the 1000 hours they spent on your game.
Performance: you don’t want to freeze the game for a second every time you load or save a game, which can happen automatically even during gameplay. Or even worse, gift your players a 1-second freeze every time you update a single value in their game state.
I have seen it all. Fragile and bad performing serialization techniques that bring pain to players. After all, we help our studio clients fix wrong implementations all the time.
While prototyping, don’t overthink this. Almost everything works. Here I recommend the simplicity using of Unity’s built-in JSON serialization:
[Serialization]
attributeJsonUtility.ToJson
for serializationJsonUtility.FromJson
for deserializationThis is perfect for things you want to throw away later on.
For production, you’ll want something more powerful AND robust. Something that supports versioning and doesn’t give you a free headache every morning which makes you quit gamedev and your relationship.
I recommend using either:
Efficient & robust solutions that work with binary formats to reduce your document output size and latency. Which is sexy for networking too by the way, not just save-games.
Of course, everything depends on your specific project and team. There are more options out there that I did not cover in this short video, even “creative” ways of using Scriptable Objects.
And there are more factors you must consider, such as
Don’t worry, the options I gave you are a good starting point. But if you want to make the BEST decision, then you must consider all these factors too.
I discuss serialization & deserialization with much deeper detail in the Performance Taskforce membership. Benchmarks, guides, benefits and blind spots of each tech (so, reasons not to choose each one). If you want to use serialization in production code, have a look at the Unity Performance Taskforce membership.
And if your studio could use a hand from our specialized team of Unity consultants, let’s have a chat, we can help.
Ruben (The GameDev Guru)