docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface IRpcCommandSerializer<T>

    Interface that must be implemented by a burst-compatible struct to serialize/deserialize the specified T type.

    A common pattern is to make the struct declaring the rpc to also implement the serialize/deserialize interface. For example:

    struct MyRpc : IComponentData, IRpcCommandSerializer{MyRpc}
    {
        public void Serialize(ref DataStreamWriter writer, in RpcSerializerState state, in MyRpc data)
        { ... }
        public void Deserialize(ref DataStreamReader reader, in RpcDeserializerState state, ref MyRpc data)
        { ... }
        PortableFunctionPointer{RpcExecutor.ExecuteDelegate} CompileExecute()
        { ... }
    }

    When declaring an rpc using the IRpcCommand interface, it is not necessary to implement the `IRpcCommandSerializer` interface yourself; the code-generation will automatically create a struct implementing the interface and all necessary boilerplate code.

    Namespace: Unity.NetCode
    Assembly: Unity.NetCode.dll
    Syntax
    public interface IRpcCommandSerializer<T> where T : struct, IComponentData
    Type Parameters
    Name Description
    T

    Component type to serialize

    Methods

    CompileExecute()

    Invoked when the rpc is registered to the RpcSystem at runtime. By declaring rpcs using IRpcCommand, this method is automatically generated. See RpcExecutor for further information on how to use it to implement your custom execute method.

    Declaration
    PortableFunctionPointer<RpcExecutor.ExecuteDelegate> CompileExecute()
    Returns
    Type Description
    PortableFunctionPointer<RpcExecutor.ExecuteDelegate>

    A valid burst-compatible function pointer of a static method that will be called after the rpc has been deserialized to actually "execute" the command.

    Deserialize(ref DataStreamReader, in RpcDeserializerState, ref T)

    Method called by the RpcSystem when an rpc is dequeued from the IncomingRpcDataStreamBuffer. Copies the data from the reader to the output data. The deserialization code is automatically generated when your struct implements the IRpcCommand interface. You must implement this method yourself when you opt-in for manual serialization.

    Declaration
    void Deserialize(ref DataStreamReader reader, in RpcDeserializerState state, ref T data)
    Parameters
    Type Name Description
    DataStreamReader reader

    Data reader

    RpcDeserializerState state

    Serializer state

    T data

    data to read into

    Serialize(ref DataStreamWriter, in RpcSerializerState, in T)

    Method called by the RpcSystem when an rpc is dequeued from the OutgoingRpcDataStreamBuffer (to be sent over the network). The serialization code is automatically generated when your struct implements the IRpcCommand interface. You must implement this method yourself when you opt-in for manual serialization.

    Declaration
    void Serialize(ref DataStreamWriter writer, in RpcSerializerState state, in T data)
    Parameters
    Type Name Description
    DataStreamWriter writer

    Data writer

    RpcSerializerState state

    Serializer state

    T data

    data to serialize

    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)