Data Persistence - Save & load your game state while avoiding common mistakes




Published: 28 Jun 2022

Learn how to save and load data in Unity - avoiding common mistakes and dangerous serialization techniques many other tutorials will tell you to use!


In this video we'll look at using text-based serialization using JSON and optionally encrypt that data. I also discuss some of the pros/cons for using text-based serialization, and what you should use instead if you really want to/need to use a binary serialization technique.


Common suggestions that you should absolutely not use to persist game state data are:

1. Player Prefs - these are not designed for storing game state. Only...Player Preferences such as graphic & audio settings.

2. BinaryFormatter - this class is dangerous and insecure. Use of this class can allow an attacker to take over the system. https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide


🔶 ALL THINGS LlamAcademy now available at: https://llamacademy.dev/support including latest tutorials, courses, ways to support, and more! Check it out 🙂

👨‍💻 Get the FULL FREE PROJECT on GitHub: https://github.com/llamacademy/persistent-data/

🏷️Save 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: https://www.jetbrains.com/store/?section=personal&billing=yearly


📚 Resources 📚

🟠 JSON.Net: https://www.newtonsoft.com/json

🟠 Encrypt/Decrypt Data with AES: https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aes?view=net-6.0

🟠 Binary Formatter Security: https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide

🟠 Unity JSON.Net Package: https://docs.unity3d.com/Packages/[email protected]/manual/index.html

🟠 Protobuf (BinaryFormatter alternative): https://github.com/protocolbuffers/protobuf

🟠 Protobuf C# Docs: https://developers.google.com/protocol-buffers/docs/csharptutorial


Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.


Connect on Social Media

Some links may be affiliate links, which at no additional cost to you, gives LlamAcademy a small portion of the purchase.