|
1 | 1 | --- |
2 | 2 | id: messaging-system |
3 | 3 | title: Sending events with RPCs |
4 | | -description: An introduction to the messaging system in Unity MLAPI, including RPC's and Custom Messages. |
5 | 4 | --- |
6 | 5 | import ImageSwitcher from '@site/src/ImageSwitcher.js'; |
7 | 6 |
|
8 | | -Netcode for GameObjects (Netcode) has two parts to its messaging system: RPCs and [Custom Messages](message-system/custom-messages.md). Both types have sub-types that change their behaviour, functionality, and performance. This page will focus on RPCs. |
| 7 | +Netcode for GameObjects has two parts to its messaging system: [remote procedure calls (RPCs)](message-system/rpc.md) and [custom messages](message-system/custom-messages.md). Both types have sub-types that change their behavior, functionality, and performance. RPCs as implemented in Netcode for GameObjects are session-mode agnostic, and work in both [client-server](../terms-concepts/client-server.md) and [distributed authority](../terms-concepts/distributed-authority.md) contexts. |
9 | 8 |
|
10 | | -## RPC: Remote Procedure Call |
| 9 | +This page provides an introduction to RPCs. For more details, refer to the pages listed in the [RPCs in Netcode for GameObjects section](#rpcs-in-netcode-for-gameobjects) |
11 | 10 |
|
12 | | -The concept of an `RPC` is common not only in video games but in the software industry in general. They're ways to call methods on objects that aren't in the same executable. |
| 11 | +## Remote procedure calls (RPCs) |
| 12 | + |
| 13 | +RPCs are a standard software industry concept. They're a way to call methods on objects that aren't in the same executable. |
13 | 14 |
|
14 | 15 | <figure> |
15 | 16 | <ImageSwitcher |
16 | 17 | lightImageSrc="/sequence_diagrams/RPCs/ServerRPCs.png?text=LightMode" |
17 | 18 | darkImageSrc="/sequence_diagrams/RPCs/ServerRPCs_Dark.png?text=DarkMode"/> |
18 | | - <figcaption>Client can invoke a server RPC on a Network Object. The RPC will be placed in the local queue and then sent to the server, where it will be executed on the server version of the same Network Object.</figcaption> |
| 19 | + <figcaption>Client can invoke a server RPC on a NetworkObject. The RPC is placed in the local queue and then sent to the server, where it's executed on the server version of the same NetworkObject.</figcaption> |
19 | 20 | </figure> |
20 | 21 |
|
21 | | -At a high level, when calling an `RPC` client side, the SDK will take a note of the object, component, method and any parameters for that `RPC` and send that information over the network. The server will receive that information, find the specified object, find the specified method and call it on the specified object with the received parameters. |
22 | | - |
23 | | -When calling an `RPC`, you call a method remotely on an object that can be anywhere in the world. They're "events" you can trigger when needed. |
| 22 | +When calling an RPC from a client, the SDK takes note of the object, component, method, and any parameters for that RPC and sends that information over the network. The server or distributed authority service receives that information, finds the specified object, finds the specified method, and calls it on the specified object with the received parameters. |
24 | 23 |
|
25 | | -If you call an `RPC` method on your side, it will execute on a different machine. |
26 | | - |
27 | | -Netcode includes multiple RPC variations that you can use to execute logic with various remote targets. To learn more about RPCs, refer to[`Rpc`](message-system/rpc.md). |
| 24 | +Netcode for GameObjects includes multiple RPC variations that you can use to execute logic with various remote targets. |
28 | 25 |
|
29 | 26 | <figure> |
30 | 27 | <ImageSwitcher |
31 | 28 | lightImageSrc="/sequence_diagrams/RPCs/ClientRPCs.png?text=LightMode" |
32 | 29 | darkImageSrc="/sequence_diagrams/RPCs/ClientRPCs_Dark.png?text=DarkMode"/> |
33 | | - <figcaption>Server can invoke a client RPC on a Network Object. The RPC will be placed in the local queue and then sent to a selection of clients (by default this selection is "all clients"). When received by a client, RPC will be executed on the client's version of the same Network Object.</figcaption> |
| 30 | + <figcaption>Server can invoke a client RPC on a NetworkObject. The RPC is placed in the local queue and then sent to a selection of clients (by default this selection is all clients). When received by a client, RPCs are executed on the client's version of the same NetworkObject.</figcaption> |
34 | 31 | </figure> |
35 | 32 |
|
| 33 | +### RPCs in Netcode for GameObjects |
36 | 34 |
|
37 | | -:::info |
38 | | -For more information see the wikipedia entry on [Remote Procedure Call's](https://en.wikipedia.org/wiki/Remote_procedure_call). |
39 | | -::: |
40 | | - |
41 | | -### Netcode's RPCs |
42 | | - |
43 | | -See the following pages for more information: |
| 35 | +Refer to the following pages for more information about how RPCs are implemented in Netcode for GameObjects. |
44 | 36 |
|
45 | | -- [Rpc](message-system/rpc.md) |
| 37 | +- [Remote procedure calls (RPCs)](message-system/rpc.md) |
46 | 38 | - [Reliability](message-system/reliabilty.md) |
47 | | -- [Execution Table](message-system/execution-table.md) |
48 | | -- [RPC Params](message-system/rpc-params.md) |
49 | | - - [Serialization Types and RPCs](message-system/../serialization/serialization-intro.md) |
| 39 | +- [RPC parameters](message-system/rpc-params.md) |
| 40 | + - [Serialization types and RPCs](message-system/../serialization/serialization-intro.md) |
50 | 41 |
|
51 | | -There is also some additional design advice on RPC's and some usage examples on the following pages: |
| 42 | +There's also some additional design advice on RPCs and some usage examples on the following pages: |
52 | 43 |
|
53 | 44 | - [RPC vs NetworkVariable](../learn/rpcvnetvar.md) |
54 | 45 | - [RPC vs NetworkVariables Examples](../learn/rpcnetvarexamples.md) |
55 | 46 |
|
56 | | -:::note Migration and Compatibility |
57 | | -See [RPC Migration and Compatibility](message-system/rpc-compatibility.md) for more information on updates, cross-compatibility, and deprecated methods for Unity RPC. |
| 47 | +:::note Migration and compatibility |
| 48 | +Refer to [RPC migration and compatibility](message-system/rpc-compatibility.md) for more information on updates, cross-compatibility, and deprecated methods for Unity RPC. |
58 | 49 | ::: |
59 | 50 |
|
60 | 51 | ## RPC method calls |
61 | 52 |
|
62 | 53 | A typical SDK user (Unity developer) can declare multiple RPCs under a `NetworkBehaviour` and inbound/outbound RPC calls will be replicated as a part of its replication in a network frame. |
63 | 54 |
|
64 | | -A method turned into an RPC is no longer a regular method, it will have its own implications on direct calls and in the network pipeline. See [Execution Table](message-system/execution-table.md). |
| 55 | +A method turned into an RPC is no longer a regular method; it will have its own implications on direct calls and in the network pipeline. |
| 56 | + |
| 57 | +### RPC usage checklist |
| 58 | + |
| 59 | +To use RPCs, make sure: |
65 | 60 |
|
66 | | -### RPC usage checklist: |
67 | | -To use RPCs, make sure |
68 | | -- ```[Rpc]``` attributes are on your method |
69 | | -- Your method name ends with ```Rpc``` (ex: ```DoSomethingRpc()```) |
70 | | -- your method is declared in a class that inherits from NetworkBehaviour |
71 | | - - your GameObject has a NetworkObject component attached |
| 61 | +- `[Rpc]` attributes are on your method |
| 62 | +- Your method name ends with `Rpc` (for example, `DoSomethingRpc()`) |
| 63 | +- Your method is declared in a class that inherits from `NetworkBehaviour` |
| 64 | + - Your GameObject has a NetworkObject component attached |
72 | 65 |
|
73 | | -## Serialization Types and RPCs |
| 66 | +## Serialization types and RPCs |
74 | 67 |
|
75 | | -Instances of Serializable Types are passed into an RPC as parameters and are serialized and replicated to the remote side. |
| 68 | +Instances of serializable types are passed into an RPC as parameters and are serialized and replicated to the remote side. |
76 | 69 |
|
77 | | -See [Serialization](serialization/serialization-intro.md) for more information. |
| 70 | +Refer to the [serialization page](serialization/serialization-intro.md) for more information. |
0 commit comments