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.
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
| RpcTarget | Who runs it | Kept for late joiners |
|---|---|---|
All | Everyone; you run it immediately | No |
Others | Everyone but you | No |
MasterClient | The master client | No |
AllViaServer | Everyone, in the order the server saw it | No |
AllBuffered | Everyone; you run it immediately | Yes, every call |
OthersBuffered | Everyone but you | Yes, every call |
AllBufferedLast | Everyone; you run it immediately | Only the latest per object and method |
OthersBufferedLast | Everyone but you | Only 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.