Skip to content

Unity SDK

RPCs

Call a method on every client, on the master client, or on one player, optionally kept for late joiners.

Declare and call

Mark the method with [SyncRPC]. It can be private and must live on a component of the same GameObject as the SyncVerseView. Add a trailing SyncVerseMessageInfo parameter to learn who sent it.

C#
public class Door : MonoBehaviour {
    SyncVerseView view;
    void Awake () => view = GetComponent<SyncVerseView> ();

    public void Toggle (bool open) =>
        // Kept for late joiners: only the latest Open call per door is replayed.
        view.RPC ("Open", RpcTarget.AllBufferedLast, open);

    [SyncRPC]
    void Open (bool open, SyncVerseMessageInfo info) {
        GetComponent<Animator> ().SetBool ("Open", open);
        Debug.Log ($"{info.Sender?.NickName} toggled the door");
    }
}

Send to one player with view.RPC("Method", player, args). Any player may call an RPC on any object.

Targets

RpcTargetWho runs itKept for late joiners
AllEveryone; you run it immediatelyNo
OthersEveryone but youNo
MasterClientThe master clientNo
AllViaServerEveryone, in the order the server saw itNo
AllBufferedEveryone; you run it immediatelyYes, every call
OthersBufferedEveryone but youYes, every call
AllBufferedLastEveryone; you run it immediatelyOnly the latest per object and method
OthersBufferedLastEveryone but youOnly the latest per object and method
All runs your copy before the network sees it. When every client must run calls in the same order, use AllViaServer.

Buffered calls are removed when their object is destroyed, and calls a player sent are removed when that player leaves.

Argument types

byte, bool, short, ushort, int, long, float, double, string, Vector2, Vector3, Quaternion, Color, byte[], int[], float[], string[] and null. Pass enums as int and anything else as byte[].

A frame is limited to 64 KiB. If the argument types do not match the method, the call is skipped and logged; the connection stays up.