- Home /
binary serialization in c#
I'm looing for solution how to serialize and de serialize binary data. I want to use BJON (Binary JSON), but i can change my decision, so i found that solution - http://james.newtonking.com/archive/2009/12/26/json-net-3-5-release-6-binary-json-bson-support.aspx . Is it works in unity or now? What you can recommend me for me?
Check it out $$anonymous$$ernys.Bson. I made it for Unity. API is simple and easy to use. ;)
Answer by SharedProphet · Aug 21, 2010 at 04:32 PM
Or if you are willing to decorate the objects you are serializing with attributes, and you're not serializing anything stored as just "object", you could try protobuf-net (Google Protocol Buffers). It is faster and serialized objects take up less space than using BinaryFormatter.
protobuf-net is awesome! doesn't work on unity iOS though.
edit: protobuf-net v2 beta is out. I've been using it on iOS and works fantastic.
Unfortunately it is not easy to serialize built-in Unity3D types like GameObject, Transform, Component in protobuf-net. So one won't get away with just using attributes if he wants to serialize those (and it is usually the case when you want to store the part of the scene). Serializing components is yet another non-trivial tasks.
GameObject Serializer Pro is built on top of protobuf-net, and includes many of the common surrogates need to serialize Components like Transform, and even entire GameObjects (This is not normally what you want unless you are creating procedural content).
Even if you are not creating procedural content, using the support for primitive types like Vector3 and Quaternion can save a lot of work.
Answer by qJake · Mar 30, 2010 at 04:34 PM
You should look into the .NET-specific class BinaryFormatter (MSDN). It will binary-serialize any ISerializable
object for you.
Answer by Zeanog · Dec 14, 2011 at 07:53 PM
Also if you want to serialize Unity objects you can try using ISerializationSurrogate
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializationsurrogate.aspx
I used it to serialize MonoBehaviours as they dont need to be created when you deserialize. You just serialize the name( or unique id ) of the game object that owns your MonoBehaviour script and then use GameObject.Find when you deserialize.
Answer by MidnightStudiosInc · Jul 01, 2015 at 03:36 PM
GameObject Serializer Pro is built on top of protobuf-net, and includes many of the common surrogates need to serialize Components like Transform, and even entire GameObjects (This is not normally what you want unless you are creating procedural content).
Even if you are not creating procedural content, using the support for primitive types like Vector3 and Quaternion can save a lot of work.
Does this package allow backwards compatible reading of save files? For example, with protobuf you'd serialize some object, and if you later change it's class definition, you can still deserialize old versions of it as long as you only added fields. This is essentially why I'm considering using protobufs, so that I won't make players' save files unreadable when I push updates. But figuring out how to get protobuf-net into my project - wow - looks like quite a pain, so I'm hoping I can just use your package.
Your answer

Follow this Question
Related Questions
JSON - Load Subset of Files Based on Key in File 0 Answers
"Asset Serialization Mode" - Is that only during development or runtime as well? 1 Answer
Upload Save (Unity Serializer) to Server 1 Answer
How do I send data to a cloud server like Amazon EC2? 1 Answer
How to serialize a reference to a ScriptableObject asset file using the JsonSerializer 2 Answers