Skip to content

Commit 8e3728a

Browse files
committed
Added RPC return value documentation
1 parent 2f65746 commit 8e3728a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/_docs/the-basics/messaging-system.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ private void MyClientRPC(int number)
5656
#### Custom Type Arguments
5757
Custom types can be sent (Classes or Structs) if they implement the IBitWritable interface.
5858

59+
#### Return Values
60+
If you use convenience RPC the MLAPI supports return values starting with version 6.0.0. The method have to return a serializable type which has the same requirements as parameters. When invoking the method you will get a ``RpcResponse<T>`` where ``T`` is the return type. Note that since this requires two way communication, the result might not be available straight away but can be waited for in a coroutine. Here is an example of a RPC with a return value.
61+
62+
```csharp
63+
public IEnumerator MyRpcCoroutine()
64+
{
65+
RpcResponse<float> response = InvokeServerRpc(MyRpcWithReturnValue, Random.Range(0f, 100f), Random.Range(0f, 100f));
66+
67+
while (!response.IsDone)
68+
{
69+
yield return null;
70+
}
71+
72+
Debug.LogFormat("The final result was {0}!", response.Value);
73+
}
74+
75+
public float MyRpcWithReturnValue(float x, float y)
76+
{
77+
return x * y;
78+
}
79+
```
80+
5981
#### Performance Example
6082
To use the performance mode, the RPC method require the following signature ``void (uint clientId, Stream readStream)`` and the sender is required to use the non generic Stream overload.
6183

0 commit comments

Comments
 (0)