New serializer using Protobuf-NET

In Wave Engine 2.3.1 we have started to use Protobuf-NET as the default serializer in all game description files (scenes, prefabs, materials, etc…).

Protobuf-NET is a contract based serializer for .NET code, that happens to write data in the “protocol buffers” serialization format engineered by Google.

The inclusion of Protobuf-NET gives us the following advantages:

  • Performance Boost: Reduce app startup time and other serialization related actions up to 5X  (scene navigations, prefab instantiations …)
  • Reduce app package size
  • Binary files: Avoid to deploy plain xml files in app packages
  • Support DataContract attributes: You don’t need to change your components code

New workflow

DataContract serializer (xml files) is still being used as the default serializer in Wave Visual Editor. This is useful to inspect scenes or upload your game project in a Version Control System (Git for example).

Protobuf-NET serializer is only used when our project is compiled and run outside of Wave Editor.

Protobuf-NET guideline for Components

In order to avoid serialization problems using Protobuf-NET, we encourage you to avoid this following scenarios in your Component code.

[DataMember] attribute cannot be used with object types

Try to avoid using [DataMember] attribute with an object type variable/property.

This will cause the following compilation error:

Initialize Field and Properties inside the DefaultValues method

Fields can only be initialized inside the DefaultValues method (it will work in Protobuf, but not in DataContract)

This will not cause an error. But different behavior between DataContract and Protobuf can be noticed.

Interfaces and Protobuf

Protobuf handles interfaces as base classes, so [DataMember] attribute cannot be used with the implemented interface and the base class at the same time.

This will cause the following compilation error:

Disable Protobuf-NET

Protobuf-NET is now the default WaveEngine serializer, but you can revert this situation and turn back to the old DataContract serializer.

To do that, follow this steps:

  • Add this line of code in your Game.cs file:

  • Edit your game .csproj file, and include the following line inside the first <PropertyGroup> tag:


Leave a Reply

Your email address will not be published. Required fields are marked *