docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Serialization

    Netcode for GameObjects has built-in serialization support for C# and Unity primitive types out-of-the-box, also with ability to further extend network serialization for user defined types implementing INetworkSerializable interface.

    Topic Description
    C# primitives C# primitive types are serialized by built-in serialization code. These types include bool, char, sbyte, byte, short, ushort, int, uint, long, ulong, float, double, and string.
    Unity primitives Unity Primitive Color, Color32, Vector2, Vector3, Vector4, Quaternion, Ray, Ray2D types will be serialized by built-in serialization code.
    Enum types A user-defined enum type will be serialized by built-in serialization code (with underlying integer type).
    Arrays Netcode for GameObjects has built-in serialization code for arrays of C# value-type primitives, like int[], and Unity primitive types. Any arrays of types that aren't handled by the built-in serialization code, such as string[], need to be handled using a container class or structure that implements the INetworkSerializable interface.
    INetworkSerializable You can use the INetworkSerializable interface to define custom serializable types.
    Custom serialization Create custom serialization types.
    NetworkObject serialization GameObjects, NetworkObjects and NetworkBehaviour aren't serializable types so they can't be used in RPCs or NetworkVariables by default. There are two convenience wrappers which can be used to send a reference to a NetworkObject or a NetworkBehaviour over RPCs or NetworkVariables.
    FastBufferWriter and FastBufferReader The serialization and deserialization is done via 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.
    In This Article
    Back to top
    Copyright © 2025 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)