Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit 2411425

Browse files
authored
Develop into main (#1264)
2 parents 37b926f + 0cd0d6e commit 2411425

19 files changed

+611
-585
lines changed

docs/advanced-topics/connection-events.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
id: connection-events
33
title: Connection events
4-
sidebar_label: Connection events
54

65
---
76

8-
When you need to react to connection or disconnection events for yourself and other clients, you can use `NetworkManager.OnConnectionEvent` as a unified source of information about changes to the network topology. `OnConnectionEvent` will receive a `ConnectionEventData` struct detailing the relevant information about the connection state change:
7+
When you need to react to connection or disconnection events for yourself or other clients, you can use `NetworkManager.OnConnectionEvent` as a unified source of information about changes in the network. Connection events are session-mode agnostic and work in both [client-server](../terms-concepts/client-server.md) and [distributed authority](../terms-concepts/distributed-authority.md) contexts.
8+
9+
`OnConnectionEvent` receives a `ConnectionEventData` struct detailing the relevant information about the connection state change:
910

1011
```csharp
1112
public enum ConnectionEvent

docs/advanced-topics/message-system/rpc.md

Lines changed: 49 additions & 55 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,70 @@
11
---
22
id: messaging-system
33
title: Sending events with RPCs
4-
description: An introduction to the messaging system in Unity MLAPI, including RPC's and Custom Messages.
54
---
65
import ImageSwitcher from '@site/src/ImageSwitcher.js';
76

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.
98

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)
1110

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.
1314

1415
<figure>
1516
<ImageSwitcher
1617
lightImageSrc="/sequence_diagrams/RPCs/ServerRPCs.png?text=LightMode"
1718
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>
1920
</figure>
2021

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.
2423

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.
2825

2926
<figure>
3027
<ImageSwitcher
3128
lightImageSrc="/sequence_diagrams/RPCs/ClientRPCs.png?text=LightMode"
3229
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>
3431
</figure>
3532

33+
### RPCs in Netcode for GameObjects
3634

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.
4436

45-
- [Rpc](message-system/rpc.md)
37+
- [Remote procedure calls (RPCs)](message-system/rpc.md)
4638
- [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)
5041

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:
5243

5344
- [RPC vs NetworkVariable](../learn/rpcvnetvar.md)
5445
- [RPC vs NetworkVariables Examples](../learn/rpcnetvarexamples.md)
5546

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.
5849
:::
5950

6051
## RPC method calls
6152

6253
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.
6354

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:
6560

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
7265

73-
## Serialization Types and RPCs
66+
## Serialization types and RPCs
7467

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.
7669

77-
See [Serialization](serialization/serialization-intro.md) for more information.
70+
Refer to the [serialization page](serialization/serialization-intro.md) for more information.

docs/advanced-topics/physics.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ While `NetworkTransform` offers interpolation as a way to smooth between delta s
6666
To have a client control their owned objects, you can use either [RPCs](message-system/rpc.md) or [NetworkVariables](../basics/networkvariables.md) on the client-side. However, this often results in the host-client's updates working as expected, but with slight jitter when a client sends updates. You might be scanning for key or device input during the `Update` to `LateUpdate` stages. Any input from the host player is applied after the `FixedUpdate` stage (i.e. physics simulation for the frame has already run), but input from client players is sent via a message and processed, with a half RTT delay, on the host side (or processed 1 network tick + half RTT if using NetworkVariables). Because of when messages are processed, client input updates run the risk of being processed during the `EarlyUpdate` stage which occurs just before the current frame's `FixedUpdate` stage.
6767

6868
To avoid this kind of scenario, it's recommended that you apply any changes received via messages to a Rigidbody _after_ the FixedUpdate has run for the current frame. If you [look at how `NetworkTransform` handles its changes to transform state](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/a2c6f7da5be5af077427eef9c1598fa741585b82/com.unity.netcode.gameobjects/Components/NetworkTransform.cs#L3028), you can see that state updates are applied during the `Update` stage, but are received during the `EarlyUpdate` stage. Following this kind of pattern when synchronizing changes to a Rigidbody via messages will help you to avoid unexpected results in your Netcode for GameObjects project.
69+
70+
The best way to address the issue of physics latency is to create a custom `NetworkTransform` with a custom physics-based interpolator. You can also use the [Network Simulator tool](../../tools/network-simulator.md) to spot issues with latency.

docs/advanced-topics/serialization/serialization-arrays.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ To serialize a `NativeArray` container, use `serializer.SerializeValue(ref Array
6969
### `NativeList<T>`
7070

7171
To serialize a `NativeList` container, you must:
72-
7372
1. Ensure your assemblies reference `Collections`.
7473
2. You must add `UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT` to your **Scriptiong Define Symbols** list.
7574
1. From the Unity Editor top bar menu, go to **Edit** > **Project Settings...** > **Player**.

docs/advanced-topics/ways-to-synchronize.md

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,46 @@ id: ways-synchronize
33
title: Synchronizing states and events
44
---
55

6-
## Introduction
7-
Netcode for GameObjects (Netcode) includes three options for synchronizing game states and/or events:
8-
- Messaging System
9-
- Remote Procedure Calls (RPCs)
10-
- Custom Messages
11-
- NetworkVariables
12-
- Handled by the "internal" messaging system and [categorized under "Networking".](../basics/networkvariable.md)
6+
Netcode for GameObjects has three options for synchronizing game states and events:
137

14-
While each of the above options can be used for the same thing, synchronizing states or events, they all have specific use cases and limitations.
8+
- Messaging system
9+
- [Remote procedure calls (RPCs)](message-system/rpc.md)
10+
- [Custom messages](message-system/custom-messages.md)
11+
- [NetworkVariables](../basics/networkvariable.md)
12+
- Handled by the internal messaging system
1513

16-
## Messaging System
17-
The Netcode messaging system provides you with the ability to handle sending and receiving messages or events. The entire messaging system supports the serialization of most primitive value `type`s as well as any classes and/or structures that implement the `INetworkSerializable` interface.
14+
While each of these options can be used to synchronize states or events, they all have specific use cases and limitations.
1815

19-
### Remote Procedure Calls
20-
RPCs can be viewed as a way to send an event notification as well as a way to handle direct communication between a server and a client (or vice versa). This is sometimes useful when the ownership scope of the `NetworkBehavior`, that the remote procedure call is declared within, belongs to the server but you still want one or more clients to be able to communicate with the associated `NetworkObject`.
21-
**Some Usage Examples:**
22-
- An Rpc with `SendTo.Server` can be used by a client to notify the server that the player is trying to use a world object (that is, a door, a vehicle, etc.)
23-
- A second Rpc with `SendTo.SpecifiedInParams` can be used by a server to notify a specific client of a special reconnection key or some other player specific information that doesn't require its state to be synchronized with all current and any future late joining client(s).
16+
## Messaging system
2417

25-
**The are several types of RPC methods,** but most are circumstantial. The ones you are most likely to use are:
18+
The Netcode for GameObjects messaging system allows you to send and receive messages or events. The system supports the serialization of most primitive value `type`s as well as any classes and/or structures that implement the `INetworkSerializable` interface.
2619

27-
- **Rpc(SendTo.Server):** A remote procedure call received by and executed on the server-side.
28-
- **Rpc(SendTo.NotServer):** A remote procedure call received by and executed on the client side. Note that this does NOT execute on the host, as the host is also the server.
29-
- **Rpc(SendTo.ClientsAndHost):** A remote procedure call received by and executed on the client side. If the server is running in host mode, this RPC will also be executed on the server (the host client).
30-
- **Rpc(SendTo.SpecifiedInParams):** A remote procedure call that will be sent to a list of client IDs provided as parameters at runtime. (By default, other `SendTo` values cannot have any client IDs passed to them to change where they are being sent, but this can also be changed by passing `AllowTargetOverride = true` to the `Rpc` attribute.
20+
### Remote procedure calls (RPCs)
3121

32-
RPCs have no limitations on who can send them - the server can invoke an RPC with `SendTo.Server`, a client can invoke an RPC with `SendTo.NotServer`, etc. If an RPC is invoked in a way that would cause it to be received by the same process that invoked it, it will be executed immediately in that process by default. Passing `DeferOverride = true` to the `Rpc` attribute will change this behavior and the RPC will be invoked at the start of the next frame.
22+
RPCs are a way of sending an event notification as well as a way of handling direct communication between a server and a client, or between clients and the [distributed authority service](../terms-concepts/distributed-authority.md). This is sometimes useful when the ownership scope of the `NetworkBehavior`, that the remote procedure call is declared within, belongs to the server but you still want one or more clients to be able to communicate with the associated `NetworkObject`.
3323

34-
[Read More About Rpcs](../advanced-topics/message-system/rpc.md)
24+
Usage examples:
3525

36-
### Custom Messages
37-
Custom messages provide you with the ability to create your own "netcode message type" to handle scenarios where you might just need to create your own custom message.
38-
[Read More About Custom Messages](../advanced-topics/message-system/custom-messages.md)
26+
- An RPC with `SendTo.Server` can be used by a client to notify the server that the player is trying to use a world object (such as a door or vehicle).
27+
- An RPC with `SendTo.SpecifiedInParams` can be used by a server to notify a specific client of a special reconnection key or some other player-specific information that doesn't require its state to be synchronized with all current and any future late-joining client(s).
3928

40-
## NetworkVariable System
41-
A NetworkVariable is most commonly used to synchronize state between both connected and late joining clients. The `NetworkVariable` system only supports non-nullable value `type`s, but also provides support for `INetworkSerializable` implementations as well you can create your own `NetworkVariable` class by deriving from the `NetworkVariableBase` abstract class. If you want something to always be synchronized with current and late-joining clients, then it's likely a good `NetworkVariable` candidate.
29+
There are many RPC methods, as outlined on the [RPC page](message-system/rpc.md#rpc-targets). The most commonly used are:
4230

43-
[Read More About NetworkVariable](../basics/networkvariable.md)
31+
- `Rpc(SendTo.Server)`: A remote procedure call received by and executed on the server side.
32+
- `Rpc(SendTo.NotServer)`: A remote procedure call received by and executed on the client side. Note that this does NOT execute on the host, as the host is also the server.
33+
- `Rpc(SendTo.ClientsAndHost)`: A remote procedure call received by and executed on the client side. If the server is running in host mode, this RPC will also be executed on the server (the host client).
34+
- `Rpc(SendTo.SpecifiedInParams)`: A remote procedure call that will be sent to a list of client IDs provided as parameters at runtime. By default, other `SendTo` values cannot have any client IDs passed to them to change where they are being sent, but this can also be changed by passing `AllowTargetOverride = true` to the `Rpc` attribute.
35+
36+
RPCs have no limitations on who can send them: the server can invoke an RPC with `SendTo.Server`, a client can invoke an RPC with `SendTo.NotServer`, and so on. If an RPC is invoked in a way that would cause it to be received by the same process that invoked it, it will be executed immediately in that process by default. Passing `DeferOverride = true` to the `Rpc` attribute will change this behavior and the RPC will be invoked at the start of the next frame.
37+
38+
Refer to the [RPC page](../advanced-topics/message-system/rpc.md) for more details.
39+
40+
### Custom messages
41+
42+
Custom messages provide you with the ability to create your own message type. Refer to the [custom messages page](../advanced-topics/message-system/custom-messages.md) for more details.
43+
44+
## NetworkVariables
45+
46+
A NetworkVariable is most commonly used to synchronize state between both connected and late-joining clients. The `NetworkVariable` system only supports non-nullable value `type`s, but also provides support for `INetworkSerializable` implementations as well. You can create your own `NetworkVariable` class by deriving from the `NetworkVariableBase` abstract class. If you want something to always be synchronized with current and late-joining clients, then it's likely a good `NetworkVariable` candidate.
47+
48+
Refer to the [NetworkVariable page](../basics/networkvariable.md) for more details.

0 commit comments

Comments
 (0)