You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .yamato/_triggers.yml
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -87,8 +87,10 @@ pr_code_changes_checks:
87
87
# Coverage on other standalone machines is present in Nightly job so it's enough to not run all of them for PRs
88
88
# desktop_standalone_test and cmb_service_standalone_test are both reusing desktop_standalone_build dependency so we run those in the same configuration on PRs to reduce waiting time.
89
89
# Note that our daily tests will anyway run both test configurations in "minimal supported" and "trunk" configurations
Welcome to the Netcode for GameObjects repository.
11
11
12
-
Netcode for GameObjects is a Unity package that provides networking capabilities to GameObject & MonoBehaviour workflows. The framework is interoperable with many low-level transports, including the official [Unity Transport Package](https://docs-multiplayer.unity3d.com/transport/current/about).
12
+
Netcode for GameObjects is a Unity package that provides networking capabilities to GameObject & MonoBehaviour workflows. The framework is interoperable with many low-level transports, including the official [Unity Transport Package](https://docs.unity3d.com/Packages/com.unity.transport@latest).
13
13
14
14
### Getting Started
15
15
16
-
Visit the [Multiplayer Docs Site](https://docs-multiplayer.unity3d.com/) for package & API documentation, as well as information about several samples which leverage the Netcode for GameObjects package.
16
+
Visit the [Multiplayer Docs Site](https://docs.unity3d.com/Manual/multiplayer.html) for package & API documentation, as well as information about several samples which leverage the Netcode for GameObjects package.
17
17
18
-
You can also jump right into our [Hello World](https://docs-multiplayer.unity3d.com/netcode/current/tutorials/helloworld) guide for a taste of how to use the framework for basic networked tasks.
18
+
You can also use our [quickstart guide](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest/?subfolder=/manual/tutorials/get-started-with-ngo.html) to get a taste of how to use the framework for basic networked tasks.
19
19
20
20
### Community and Feedback
21
21
22
-
For general questions, networking advice or discussions about Netcode for GameObjects, please join our [Discord Community](https://discord.gg/FM8SE9E) or create a post in the [Unity Multiplayer Forum](https://forum.unity.com/forums/multiplayer.26/).
22
+
For general questions, networking advice or discussions about Netcode for GameObjects, please join our [Discord Community](https://discord.gg/unity) or create a post in the [Unity Forum's "Netcode for GameObjects" section](https://discussions.unity.com/tag/Netcode-for-GameObjects).
23
23
24
24
### Compatibility
25
25
@@ -48,4 +48,4 @@ We are an open-source project and we encourage and welcome contributions. If you
48
48
49
49
If you have an issue, bug or feature request, please follow the information in our [contribution guidelines](CONTRIBUTING.md) to submit an issue.
50
50
51
-
You can also check out our public [roadmap](https://unity.com/roadmap/unity-platform/multiplayer-networking) to get an idea for what we might be working on next!
51
+
You can also check out our public [roadmap](https://unity.com/roadmap#unity-platform-multiplayer) to get an idea for what we might be working on next!
The CMB Service is a tool that is external to our repository. The tool is inside the `runtime` folder in the [mps-common-multiplayer-backend](https://github.com/Unity-Technologies/mps-common-multiplayer-backend) repository.
4
+
5
+
Due to this, there is some more setup needed when running tests against the CMB Service.
6
+
7
+
## Configuration
8
+
9
+
The tests are automatically configured to run any `HostOrServer.DAHost` or `NetworkTopologyTypes.DistributedAuthority` test against the CMB server when either the `USE_CMB_SERVICE` scripting define is set, or when an environment variable is passed in with `USE_CMB_SERVICE=true`. When set, all non-distributed authority compatible tests will be ignored.
10
+
11
+
By default, the tests are configured to look for the service on the local machine (`localhost`/`http://127.0.0.1`) at port `7789`.
12
+
13
+
## Running against the service
14
+
15
+
First, ensure the `USE_CMB_SERVICE` scripting define or environment variable is set.
16
+
17
+
### Download the service
18
+
19
+
Go to the `CMB Runtime CI` action inside the cmb repo ([link here](https://github.com/Unity-Technologies/mps-common-multiplayer-backend/actions/workflows/runtime.yaml)). Open the most recent job and scroll down to the bottom of the page (You may have to scroll in the sidebar on the left, the centre of the page is not scrollable).
20
+
21
+
Inside the **Artifacts** section at the bottom of the page, download the `comb-server-<platform>-latest` that matches your computer architecture. This will download a pre-built binary of the most recent CMB Service.
22
+
23
+
### Run the service locally
24
+
25
+
Next we'll run the binary on the command line.
26
+
27
+
> [!NOTE]
28
+
> If you're running on macOS, you'll have to add execution privileges to the binary before running it.
29
+
30
+
```bash
31
+
xattr -c /path/to/comb-server
32
+
```
33
+
34
+
To run the service, run the following command:
35
+
36
+
```bash
37
+
/path/to/download/comb-server -l info --metrics-port 5000 standalone --port 7789 -t 60m
38
+
```
39
+
40
+
Note that we have set the port to `7789` to match where the tests will be looking.
41
+
42
+
After each test, all connected clients will disconnect from the service. The service will automatically shut down when that happens. When running multiple tests in a row, it can be more convenient to run the service in a loop:
With `USE_CMB_SERVICE` set, everything should be configured so that running any distributed authority test in the editor should run against the service we have running on the command line. Try running a test to validate that information is logged in the command line.
51
+
52
+
## Further configuration
53
+
54
+
The following environment variables allow for further configuration of the setup.
55
+
56
+
`CMB_SERVICE_PORT` defines the port where the tests will try to connect to the service (defaults to `7789`).
57
+
58
+
`NGO_HOST` defines the http address where the tests will try to connect to the service (defaults to `127.0.0.1`).
- Added new fields to the `SceneMap` struct when using Unity 6.3 or higher. These fields allow referencing scene handles via the new `SceneHandle` struct. (#3734)
14
16
15
17
### Changed
16
18
19
+
- Better error message when using generic IEquatable in a generic INetworkSerializable class and updated documentation with workaround. (#3739)
17
20
- The `NetworkManager` functions `GetTransportIdFromClientId` and `GetClientIdFromTransportId` will now return `ulong.MaxValue` when the clientId or transportId do not exist. (#3707)
18
21
- Changed NetworkShow to send a message at the end of the frame and force a NetworkVariable synchronization prior to generating the CreateObjectMessage as opposed to waiting until the next network tick to synchronize the show with the update to NetworkVariables. (#3664)
19
22
- Changed NetworkTransform now synchronizes `NetworkTransform.SwitchTransformSpaceWhenParented` when it is updated by the motion model authority. (#3664)
@@ -24,16 +27,18 @@ Additional documentation and release notes are available at [Multiplayer Documen
24
27
25
28
### Deprecated
26
29
30
+
- Deprecated all `RequireOwnership` fields around the RPCs in favor of the `RpcInvokePermission`. (#3731)
31
+
- On Unity 6.5 some `SceneMap` fields that use an `int` to represent a `SceneHandle` are deprecated. (#3734)
27
32
28
33
### Removed
29
34
30
-
31
35
### Fixed
32
36
33
37
- Multiple disconnect events from the same transport will no longer disconnect the host. (#3707)
34
38
- Fixed NetworkTransform state synchronization issue when `NetworkTransform.SwitchTransformSpaceWhenParented` is enabled and the associated NetworkObject is parented multiple times in a single frame or within a couple of frames. (#3664)
35
39
- Fixed issue when spawning, parenting, and immediately re-parenting when `NetworkTransform.SwitchTransformSpaceWhenParented` is enabled. (#3664)
36
40
- Fixed issue where the disconnect event and provided message was too generic to know why the disconnect occurred. (#3551)
41
+
- Exception when the network prefab list in the network manager has uninitialized elements. (#3739)
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Documentation~/advanced-topics/message-system/rpc.md
+112-2Lines changed: 112 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# RPC
2
2
3
-
Any process can communicate with any other process by sending a remote procedure call (RPC). As of Netcode for GameObjects version 1.8.0, the`Rpc` attribute encompasses server to client RPCs, client to server RPCs, and client to client RPCs.
3
+
Any process can communicate with any other process by sending a remote procedure call (RPC). The `Rpc` attribute is the recommended attribute to use when declaring RPC methods. The`Rpc` attribute's parameters define the receivers and execution rights for the RPC method.
|`Delivery`| Controls whether the delivery is reliable (default) or unreliable.<br /><br />Options: `RpcDelivery.Reliable` or `RpcDelivery.Unreliable`<br />Default: `RpcDelivery.Reliable`|
207
-
|`RequireOwnership`|If `true`, this RPC throws an exception if invoked by a player that does not own the object. This is in effect for server-to-client, client-to-server, and client-to-client RPCs - i.e., a server-to-client RPC will still fail if the server is not the object's owner.<br /><br />Default: `false`|
207
+
|`InvokePermission`|Sets an RPC's invocation permissions.<br /><br />Options:<br /> `RpcInvokePermission.Server` - This RPC throws an exception if invoked by a game client that is not the server.<br />`RpcInvokePermission.Owner` - This RPC throws an exception if invoked by a game client that does not own the object.<br />`RpcInvokePermission.Everyone` - This can be invoked by any connected game client.<br />Default: `RpcInvokePermission.Everyone`|
208
208
|`DeferLocal`| If `true`, RPCs that execute locally will be deferred until the start of the next frame, as if they had been sent over the network. (They will not actually be sent over the network, but will be treated as if they were.) This is useful for mutually recursive RPCs on hosts, where sending back and forth between the server and the "host client" will cause a stack overflow if each RPC is executed instantly; simulating the flow of RPCs between remote client and server enables this flow to work the same in both contexts.<br /><br />Default: `false`|
209
209
|`AllowTargetOverride`| By default, any `SendTo` value other than `SendTo.SpecifiedInParams` is a hard-coded value that cannot be changed. Setting this to `true` allows you to provide an alternate target at runtime, while using the `SendTo` value as a fallback if no runtime value is provided. |
210
210
@@ -215,6 +215,116 @@ There are a few other parameters that can be passed to either the `Rpc` attribut
215
215
|`Target`| Runtime override destination for the RPC. (See above for more details.) Populating this value will throw an exception unless either the `SendTo` value for the RPC is `SendTo.SpecifiedInParams`, or `AllowTargetOverride` is `true`.<br /><br />Default: `null`|
216
216
|`LocalDeferMode`| Overrides the `DeferLocal` value. `DeferLocalMode.Defer` causes this particular invocation of this RPC to be deferred until the next frame even if `DeferLocal` is `false`, while `DeferLocalMode.SendImmediate` causes the RPC to be executed immediately on the local machine even if `DeferLocal` is `true`. `DeferLocalMode.Default` does whatever the `DeferLocal` value in the attribute is configured to do.<br /><br />Options: `DeferLocalMode.Default`, `DeferLocalMode.Defer`, `DeferLocalMode.SendImmediate`<br />Default: `DeferLocalMode.Default`|
217
217
218
+
## Invocation order
219
+
220
+
Rpc message sent with `RpcDelivery.Reliable` will be sent and invoked on other game clients in the same order as they were called on the local game client.
Debug.Log($"client {rpcParams.Receive.SenderClientId} has opened door {doorId}");
227
+
228
+
// Server can handle door opening here
229
+
}
230
+
231
+
[Rpc(SendTo.Server)]
232
+
voidOpenChestRPC(intchestId, RpcParamsrpcParams)
233
+
{
234
+
Debug.Log($"client {rpcParams.Receive.SenderClientId} has opened chest {chestId}");
235
+
236
+
// Server can handle door opening here
237
+
}
238
+
239
+
voidUpdate()
240
+
{
241
+
if (IsClient&&Input.GetKeyDown(KeyCode.O))
242
+
{
243
+
OpenDoorRpc(1)
244
+
OpenDoorRpc(2)
245
+
OpenChestRpc(5)
246
+
}
247
+
248
+
// Other clients will log:
249
+
//
250
+
// "client 1 has opened door 1"
251
+
// "client 1 has opened door 2"
252
+
// "client 1 has opened chest 5"
253
+
}
254
+
```
255
+
256
+
> [!Warning]
257
+
> Invocation order is not guaranteed with nested RPC invocations that include targets that may invoke locally. Invocation order is also not guaranteed when using `RpcDelivery.Unreliable`
258
+
259
+
### Deferring local invocation
260
+
261
+
Invoking an RPC from within another RPC introduces the risk that the local RPC may invoke before messages are sent to other game clients. This will result in the RPC message for the inner RPC invocation being sent before the message for the outer RPC.
Debug.Log($"client {rpcParams.Receive.SenderClientId} is trying to open door {doorId}");
268
+
269
+
if (HasAuthority) {
270
+
// Authority handles opening the door here
271
+
272
+
// If the authority is invoking TryOpenDoorRpc locally before the authority has sent TryOpenDoorRpc to other clients, OpenDoorRpc will be sent before TryOpenDoorRpc.
Debug.Log($"client {rpcParams.Receive.SenderClientId} marked door {doorId} as open");
281
+
}
282
+
283
+
voidUpdate()
284
+
{
285
+
if (Input.GetKeyDown(KeyCode.O))
286
+
{
287
+
// Invocation of TryOpenDoorRpc and OpenDoorRpc may be inverted depending on the context in which TryOpenDoorRpc is invoked
288
+
TryOpenDoorRpc(20);
289
+
}
290
+
}
291
+
```
292
+
293
+
Use the RPC `LocalDeferMode` to resolve issue. Configuring the RPC to be deferred when invoked locally will ensure that any outer RPC messages are always sent before the inner function is invoked.
294
+
295
+
```csharp
296
+
// An RPC can be configured to defer the local invocation in the attribute definition
0 commit comments