From 148aaeb6c5cd7b7b0f2370c88f01f508528d6766 Mon Sep 17 00:00:00 2001 From: Chris Langsenkamp Date: Wed, 30 Jan 2019 20:31:56 -0500 Subject: [PATCH] Update RemoteActions.md (#362) Fixes #339 --- docs/Concepts/Communications/RemoteActions.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/Concepts/Communications/RemoteActions.md b/docs/Concepts/Communications/RemoteActions.md index 303031aac..3867f7316 100644 --- a/docs/Concepts/Communications/RemoteActions.md +++ b/docs/Concepts/Communications/RemoteActions.md @@ -79,6 +79,35 @@ class Player : NetworkBehaviour When running a game as a host with a LocalClient, ClientRpc calls will be invoked on the LocalClient - even though it is in the same process as the server. So the behaviour of LocalClients and RemoteClients is the same for ClientRpc calls. +## TargetRpc Calls + +TargetRpc functions are called by user code on the server, and then invoked on the corresponding client object on the client of the specified NetworkConnection. The arguments to the RPC call are serialized across the network, so that the client function is invoked with the same values as the function on the server. These functions must begin with the prefix "Target" and cannot be static. + +The first argument to an TargetRpc function must be a NetworkConnection object. + +This example shows how a client can use a Command to make a request from the server (CmdTest) by including its own `connectionToClient` as one of the parameters of the TargetRpc invoked directly from that Command: + +```cs +using UnityEngine; +using UnityEngine.Networking; + +public class Example : NetworkBehaviour +{ + [Command] + void CmdTest() + { + TargetDoMagic(connectionToClient, 55); + } + + [TargetRpc] + public void TargetDoMagic(NetworkConnection target, int extra) + { + // This output will appear on the client that called the [Command] above + Debug.Log("Magic = " + (123 + extra)); + } +} +``` + ## Arguments to Remote Actions The arguments passed to commands and ClientRpc calls are serialized and sent over the network. These arguments can be: