Struct RpcExecutor
Struct that can be used to simplify writing systems and jobs that deserialize and execute received rpc commands.
Inherited Members
Namespace: Unity.Netcode
Assembly: Unity.NetCode.dll
Syntax
[MovedFrom(true, "Unity.NetCode", null, null)]
public struct RpcExecutor
Methods
ExecuteCreateRequestComponentWithAutoInvoke<TActionSerializer, TActionRequest>(ref Parameters, RPCInvokeID)
Same as ExecuteCreateRequestComponent but also allows specification of an AutoInvokeId. This allows the RPC to be created and automatically invoked by its handler function. There should be no need to use this directly.
Declaration
public static Entity ExecuteCreateRequestComponentWithAutoInvoke<TActionSerializer, TActionRequest>(ref RpcExecutor.Parameters parameters, RPCInvokeID autoInvokeId) where TActionSerializer : struct, IRpcCommandSerializer<TActionRequest> where TActionRequest : unmanaged, ICustomMessage
Parameters
| Type | Name | Description |
|---|---|---|
| RpcExecutor.Parameters | parameters | Container for EntityCommandBuffer, JobIndex, as well as connection entity. |
| RPCInvokeID | autoInvokeId | The Id of the Remote being invoked. |
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 IComponentData. |
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 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 IComponentData. |