Serialization overview
Netcode for GameObjects uses a default serialization pipeline when using RPC's, NetworkVariables, or any other Netcode-related tasks that require serialization. The serialization pipeline looks like this:
Custom types => Built-in types => INetworkSerializable
When Netcode for GameObjects first receives a type, it checks for any custom types that you have registered for serialization, then it checks if it's a built-in type, such as a Vector3 or a float. These are handled by default. Otherwise, it checks if the type inherits INetworkSerializable, and if it does, it calls its write methods.
By default, any type that satisfies the unmanaged generic constraint can be automatically serialized as RPC parameters. This includes all basic types (bool, byte, int, float, enum, for example), as well as any structs that contain only these basic types.
Serialization and deserialization is done via the structs FastBufferWriter and FastBufferReader. These have methods for serializing individual types and methods for serializing packed numbers, but in particular provide a high-performance method called WriteValue()/ReadValue() (for Writers and Readers, respectively) that can extremely quickly write an entire unmanaged struct to a buffer.
FastBufferWriter and FastBufferReader also contain the functions FastBufferWriter.WriteNetworkSerializable() and FastBufferReader.ReadNetworkSerializable for writing and reading values that use the INetworkSerializable interface.
Built-in serialization
Custom serialization
- INetworkSerializable
- INetworkSerializeByMemcpy
- Customizing serialization
- Custom NetworkVariable implementations