Class RpcTarget
Implementations of the various SendTo options, as well as additional runtime-only options Single(ulong, RpcTargetUse), Group(NativeArray<ulong>), Group(NativeList<ulong>), Group(ulong[]), Group<T>(T), Not(ulong), Not(NativeArray<ulong>), Not(NativeList<ulong>), Not(ulong[]), and Not<T>(T)
Inherited Members
Namespace: Unity.Netcode
Assembly: Unity.Netcode.Runtime.dll
Syntax
public class RpcTarget
Fields
Authority
Send this RPC to the authority. In distributed authority mode, this will be the owner of the NetworkObject. In normal client-server mode, this is basically the exact same thing as a server rpc.
Declaration
public BaseRpcTarget Authority
Field Value
Type | Description |
---|---|
BaseRpcTarget |
ClientsAndHost
Send this RPC to all clients, including the host, if a host exists. If the server is running in host mode, this is the same as Everyone. If the server is running in dedicated server mode, this is the same as NotServer.
Declaration
public BaseRpcTarget ClientsAndHost
Field Value
Type | Description |
---|---|
BaseRpcTarget |
Everyone
Send this RPC to everone, filtered to the current observer list. Will execute locally.
Declaration
public BaseRpcTarget Everyone
Field Value
Type | Description |
---|---|
BaseRpcTarget |
Me
Execute this RPC locally.
Normally this is no different from a standard function call.
Using the DeferLocal parameter of the attribute or the LocalDeferMode override in RpcSendParams,
this can allow an RPC to be processed on localhost with a one-frame delay as if it were sent over
the network.
Declaration
public BaseRpcTarget Me
Field Value
Type | Description |
---|---|
BaseRpcTarget |
NotAuthority
Send this RPC to all non-authority instances. In distributed authority mode, this will be the non-owners of the NetworkObject. In normal client-server mode, this is basically the exact same thing as a client rpc.
Declaration
public BaseRpcTarget NotAuthority
Field Value
Type | Description |
---|---|
BaseRpcTarget |
NotMe
Send this RPC to everyone but the local machine, filtered to the current observer list.
Declaration
public BaseRpcTarget NotMe
Field Value
Type | Description |
---|---|
BaseRpcTarget |
NotOwner
Send to everyone but the current owner, filtered to the current observer list. Will execute locally if the local process is not the owner.
Declaration
public BaseRpcTarget NotOwner
Field Value
Type | Description |
---|---|
BaseRpcTarget |
NotServer
Send to everyone but the server, filtered to the current observer list.
Will NOT send to a server running in host mode - it is still treated as a server.
If you want to send to servers when they are host, but not when they are dedicated server, use
ClientsAndHost.
Will execute locally if invoked on a client.
Will NOT execute locally if invoked on a server running in host mode.
Declaration
public BaseRpcTarget NotServer
Field Value
Type | Description |
---|---|
BaseRpcTarget |
Owner
Send to the NetworkObject's current owner. Will execute locally if the local process is the owner.
Declaration
public BaseRpcTarget Owner
Field Value
Type | Description |
---|---|
BaseRpcTarget |
Server
Send to the server, regardless of ownership. Will execute locally if invoked on the server.
Declaration
public BaseRpcTarget Server
Field Value
Type | Description |
---|---|
BaseRpcTarget |
Methods
Dispose()
Invoked when this class is disposed.
Declaration
public void Dispose()
Group(ulong[], RpcTargetUse)
Sends to a group of client IDs. Constructing arrays requires garbage collected allocations. This override is only recommended if you either have no strict performance requirements, or have the group of client IDs cached so it is not created each time.
Declaration
public BaseRpcTarget Group(ulong[] clientIds, RpcTargetUse use)
Parameters
Type | Name | Description |
---|---|---|
ulong[] | clientIds | The IDs of the client that should receive the message. |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Not() or Group(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to all clients except the specified one. The type of target (cached or new instance) depends on the |
Group(NativeArray<ulong>, RpcTargetUse)
Sends to a group of client IDs. NativeArrays can be trivially constructed using Allocator.Temp, making this an efficient Group method if the group list is dynamically constructed.
Declaration
public BaseRpcTarget Group(NativeArray<ulong> clientIds, RpcTargetUse use)
Parameters
Type | Name | Description |
---|---|---|
NativeArray<ulong> | clientIds | The IDs of the client that should receive the message. |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Not() or Group(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to all clients except the specified one. The type of target (cached or new instance) depends on the |
Group(NativeList<ulong>, RpcTargetUse)
Sends to a group of client IDs. NativeList can be trivially constructed using Allocator.Temp, making this an efficient Group method if the group list is dynamically constructed.
Declaration
public BaseRpcTarget Group(NativeList<ulong> clientIds, RpcTargetUse use)
Parameters
Type | Name | Description |
---|---|---|
NativeList<ulong> | clientIds | The IDs of the client that should receive the message. |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Not() or Group(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to all clients except the specified one. The type of target (cached or new instance) depends on the |
Group<T>(T, RpcTargetUse)
Sends to a group of client IDs. This accepts any IEnumerable type, such as List<ulong>, but cannot be called without a garbage collected allocation (even if the type itself is a struct type, due to boxing). This override is only recommended if you either have no strict performance requirements, or have the group of client IDs cached so it is not created each time.
Declaration
public BaseRpcTarget Group<T>(T clientIds, RpcTargetUse use) where T : IEnumerable<ulong>
Parameters
Type | Name | Description |
---|---|---|
T | clientIds | The IDs of the client that should receive the message. |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Not() or Group(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to all clients except the specified one. The type of target (cached or new instance) depends on the |
Type Parameters
Name | Description |
---|---|
T | The type |
Not(ulong, RpcTargetUse)
Send to everyone EXCEPT a specific single client ID.
Declaration
public BaseRpcTarget Not(ulong excludedClientId, RpcTargetUse use)
Parameters
Type | Name | Description |
---|---|---|
ulong | excludedClientId | The IDs of the client to exclude from receiving the message |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Not() or Group(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to all clients except the specified one. The type of target (cached or new instance) depends on the |
Not(ulong[], RpcTargetUse)
Sends to everyone EXCEPT a group of client IDs. Constructing arrays requires garbage collected allocations. This override is only recommended if you either have no strict performance requirements, or have the group of client IDs cached so it is not created each time.
Declaration
public BaseRpcTarget Not(ulong[] excludedClientIds, RpcTargetUse use)
Parameters
Type | Name | Description |
---|---|---|
ulong[] | excludedClientIds | The IDs of the client to exclude from receiving the message |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Not() or Group(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to all clients except the specified one. The type of target (cached or new instance) depends on the |
Not(NativeArray<ulong>, RpcTargetUse)
Sends to everyone EXCEPT a group of client IDs. NativeArrays can be trivially constructed using Allocator.Temp, making this an efficient Group method if the group list is dynamically constructed.
Declaration
public BaseRpcTarget Not(NativeArray<ulong> excludedClientIds, RpcTargetUse use)
Parameters
Type | Name | Description |
---|---|---|
NativeArray<ulong> | excludedClientIds | The IDs of the client to exclude from receiving the message |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Not() or Group(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to all clients except the specified one. The type of target (cached or new instance) depends on the |
Not(NativeList<ulong>, RpcTargetUse)
Sends to everyone EXCEPT a group of client IDs. NativeList can be trivially constructed using Allocator.Temp, making this an efficient Group method if the group list is dynamically constructed.
Declaration
public BaseRpcTarget Not(NativeList<ulong> excludedClientIds, RpcTargetUse use)
Parameters
Type | Name | Description |
---|---|---|
NativeList<ulong> | excludedClientIds | The IDs of the client to exclude from receiving the message |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Not() or Group(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to all clients except the specified one. The type of target (cached or new instance) depends on the |
Not<T>(T, RpcTargetUse)
Sends to everyone EXCEPT a group of client IDs. This accepts any IEnumerable type, such as List<ulong>, but cannot be called without a garbage collected allocation (even if the type itself is a struct type, due to boxing). This override is only recommended if you either have no strict performance requirements, or have the group of client IDs cached so it is not created each time.
Declaration
public BaseRpcTarget Not<T>(T excludedClientIds, RpcTargetUse use) where T : IEnumerable<ulong>
Parameters
Type | Name | Description |
---|---|---|
T | excludedClientIds | The IDs of the client to exclude from receiving the message |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Not() or Group(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to all clients except the specified one. The type of target (cached or new instance) depends on the |
Type Parameters
Name | Description |
---|---|
T | The type |
Single(ulong, RpcTargetUse)
Send to a specific single client ID.
Declaration
public BaseRpcTarget Single(ulong clientId, RpcTargetUse use)
Parameters
Type | Name | Description |
---|---|---|
ulong | clientId | The ID of the client to send to |
RpcTargetUse | use | Temp will return a cached target, which should not be stored as it will
be overwritten in future calls to Single(). Do not call Dispose() on Temp targets. |
Returns
Type | Description |
---|---|
BaseRpcTarget | A BaseRpcTarget configured to send to the specified client. The type of target (cached or new instance) depends on the |