docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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

    • C# primitives
    • Unity primitives
    • Enum types
    • Arrays
    • Collections

    Custom serialization

    • INetworkSerializable
    • INetworkSerializeByMemcpy
    • Customizing serialization
    • Custom NetworkVariable implementations

    Additional resources

    • NetworkObject serialization
    • FastBufferWriter and FastBufferReader
    • BufferSerializer
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)