docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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)

    Inheritance
    object
    RpcTarget
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    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()

    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
    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 Description
    BaseRpcTarget

    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
    Type Description
    BaseRpcTarget

    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
    Type Description
    BaseRpcTarget

    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 Description
    BaseRpcTarget
    Type Parameters
    Name Description
    T

    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
    Type Description
    BaseRpcTarget

    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
    Type Description
    BaseRpcTarget

    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
    Type Description
    BaseRpcTarget

    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
    Type Description
    BaseRpcTarget

    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 Description
    BaseRpcTarget
    Type Parameters
    Name Description
    T

    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
    Type Description
    BaseRpcTarget
    In This Article
    Back to top
    Copyright © 2024 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)