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)
Assembly: Unity.Netcode.Runtime.dll
Syntax
Fields
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
Everyone
Send this RPC to everone, filtered to the current observer list.
Will execute locally.
Declaration
public BaseRpcTarget Everyone
Field Value
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
Field Value
NotMe
Send this RPC to everyone but the local machine, filtered to the current observer list.
Declaration
public BaseRpcTarget NotMe
Field Value
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
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
Owner
Send to the NetworkObject's current owner.
Will execute locally if the local process is the owner.
Declaration
public BaseRpcTarget Owner
Field Value
Server
Send to the server, regardless of ownership.
Will execute locally if invoked on the server.
Declaration
public BaseRpcTarget Server
Field Value
Methods
Dispose()
Declaration
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 |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
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 |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
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 |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
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 |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
Type Parameters
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 |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
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 |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
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 |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
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 |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
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 |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
Type Parameters
Single(ulong, RpcTargetUse)
Send to a specific single client ID.
Declaration
public BaseRpcTarget Single(ulong clientId, RpcTargetUse use)
Parameters
Type |
Name |
Description |
ulong |
clientId |
|
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.
Persistent will
return a new target, which can be stored, but should not be done frequently because it results in a GC allocation. You must call Dispose() on Persistent targets when you are done with them.
|
Returns
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.