BSON is deprecated in the json saving system

Hello! I think this is is more directed at Brian. Firstly thank you so much for working on this new Json saving system for us.
I’ve followed the gitlab link tutorial and downloaded the package at the end of it to open on a new unity project but it throws a warning “CS0618: ‘BsonWriter’ is obsolete: 'BSON reading and writing has been moved to its own package”. Is there an alternative to BSON? Or is this warning not relevant and if so, how to remove it?

I’m also wondering if this saving system is still the “most updated” way to save? Sure, BSON is only a problem on the encryption stage of it, the main system works fine, but I wonder because not only the Newtonsoft package not even shows up in the package list anymore (I had to add it through com.unity.nuget.newtonsoft-json) it also says “Most Unity users will be better suited using the existing json tools built into Unity”. I’m not an experienced dev but do they mean System.Text.Json? Is this the one that doesn’t support dictionaries you mentioned in the tutorial? On a side note, I found a reddit post of people mentioning System.Text.Json is more used nowadays than Newtonsoft and as you know this saving system much better than anyone I was curious to know your take on that.

I’m currently (actually literally right now) working on a major update to the Json Saving System, making it more portable (easier to adapt to a new game), and taking the time to explain exactly how it works, much like Sam does with the BinaryFormatter.

I recommend removing references to Bson within the system. It won’t be included in the new version for exactly this reason. You could go with an older version of the Newtonsoft package, but I recommend against that. The best version to use is the one that is downloaded automatically with com.unity.nuget.newtonsoft-json. This version eliminates the need for those pesky IDictionary<string, JToken> stateDict = state;casts. You'll be able to use JObject *just* like it was aDictionary<string, JToken>`.
For several versions of 2021 and 2022, this was installed automatically with certain packages, but as of version 3, they rejiggered all of their packages to no longer require NewtonSoft (a big mistake, IMO).

That’s Unity’s polite way of saying “you probably don’t know enough about advanced Json serialization to attempt to use NewtonSoft”. While we won’t be going into the deepest of NewtonSoft’s functionality, in order to use JObject, JToken, JArray, and JValue, we need NewtonSoft. This deep dive version will take the time to dig into the weeds of how these classes work.

No. They mean Unity - Scripting API: JsonUtility. While they have adapted all of their packages to use JsonUtility, I found it completely unworkable for cloning the RPG Saving System.

System.Text.Json does have utilities for conversion to Dictionaries and Lists/Arrays, and is a good start. Neither NewtonSoft.Json or System.Text.Json deal well with classes that are not [System.Serializable] (which is not the same thing as [SerializeField]. Vector3 is a fine example. In every case, you have to create special converters. The problem that exists in both NewtonSoft and System versions of Json is that even when using the serializers provided (NewtonSoft has an optional Serializer library that handles Vector3, for example) the system works great in the Editor but everything falls apart within the Player where if you compile to IL2CPP (and if you don’t, you should be), Unity’s Linker decides not to link the custom converter classes, and while there are tricks to making those serializers link, they’re very unreliable.

Using NewtonSoft, it’s much easier to convert a Vector3 to a JToken (via JObject) and back again manually than it is to try to force a custom Serializer to link.
I’d rather spend the time teaching you the how-tos of converting a class or struct to and from a JToken than teaching you how to trick the Linker into linking the serializers. You’re going to learn a lot more doing this via NewtonSoft (and that’s how I try to approach all my tutorials not always successfully)

When the new Saving System is ready to go, I will be making announcements (hopefully, I can get an announcement through our email system) to make sure that everybody knows that it’s there.

Wow thank you for such a complete answer! I feel lucky you’re working on an update because I really like this saving system and want to keep using it. I think the way you explain on gitlab is very conscise, and personally I prefer it over the more in depth one like Sam’s (but I guess it’s because I’m too impatient and want to implement things quickly lol). But I’m looking forward to whatever you’re cooking there! Good luck.

The new one is going to be a bit of a hybrid. I’m going into some more detail about how the JToken based classes work, but that can be skipped. On the other hand a firm understanding of these things should make students better at applying the saving system to any game they wish.

1 Like

Privacy & Terms