docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct RpcExecutor

    Struct that can be used to simplify writing systems and jobs that deserialize and execute received rpc commands.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.NetCode
    Assembly: Unity.NetCode.dll
    Syntax
    public struct RpcExecutor

    Methods

    ExecuteCreateRequestComponent<TActionSerializer, TActionRequest>(ref Parameters)

    Helper method that can be used to implement the execute method for the IRpcCommandSerializer<T> interface. By calling the ExecuteCreateRequestComponent, a new entity (with a TActionRequest and a ReceiveRpcCommandRequest component) is created. It is the users responsibility to write a system that consumes the created rpcs entities. For example:

    public struct MyRpcConsumeSystem : ISystem
    {
       private Query rcpQuery;
       public void OnCreate(ref SystemState state)
       {
           var builder = new EntityQueryBuilder(Allocator.Temp).WithAll<MyRpc, ReceiveRpcCommandRequestComponent>();
           rcpQuery = state.GetEntityQuery(builder);
       }
       public void OnUpdate(ref SystemState state)
       {
            foreach(var rpc in SystemAPI.Query<MyRpc>().WithAll<ReceiveRpcCommandRequestComponent>())
            {
                //do something with the rpc
            }
            //Consumes all of them
            state.EntityManager.DestroyEntity(rpcQuery);
       }
    }
    Declaration
    public static Entity ExecuteCreateRequestComponent<TActionSerializer, TActionRequest>(ref RpcExecutor.Parameters parameters) where TActionSerializer : struct, IRpcCommandSerializer<TActionRequest> where TActionRequest : unmanaged, IComponentData
    Parameters
    Type Name Description
    RpcExecutor.Parameters parameters

    Container for Unity.Entities.EntityCommandBuffer, JobIndex, as well as connection entity.

    Returns
    Type Description
    Entity

    Created entity for RPC request. Name of the Entity is set as 'NetCodeRPC'.

    Type Parameters
    Name Description
    TActionSerializer

    Struct of type IRpcCommandSerializer<T>.

    TActionRequest

    Unmanaged type of Unity.Entities.IComponentData.

    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)