Skip to content

Commit 25d9812

Browse files
Merge branch 'develop-2.0.0' into fix/networkmanager-start-from-onstopped
2 parents 1b2c652 + 9b92ec1 commit 25d9812

File tree

19 files changed

+448
-113
lines changed

19 files changed

+448
-113
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,32 @@ Additional documentation and release notes are available at [Multiplayer Documen
1010

1111
### Added
1212

13-
- Added a `WebSocketPath` field to `UnityTransport.ConnectionData` (which also shows up in the inspector if "Use WebSockets" is checked) that controls the path clients will connect to and servers/hosts will listen on when using WebSockets. (#3901)
14-
- `NetworkTransport.EarlyUpdate` and `NetworkTransport.PostLateUpdate` are now public. For the vast majority of users, there's really no point in ever calling those methods directly (the `NetworkManager` handles it). It's only useful if wrapping transports outside of NGO. (#3890)
1513

1614
### Changed
1715

1816

1917
### Deprecated
2018

2119

20+
### Removed
21+
22+
23+
### Fixed
24+
25+
26+
### Security
27+
28+
29+
### Obsolete
30+
31+
32+
## [2.11.0] - 2026-03-19
33+
34+
### Added
35+
36+
- Added a `WebSocketPath` field to `UnityTransport.ConnectionData` (which also shows up in the inspector if "Use WebSockets" is checked) that controls the path clients will connect to and servers/hosts will listen on when using WebSockets. (#3901)
37+
- `NetworkTransport.EarlyUpdate` and `NetworkTransport.PostLateUpdate` are now public. For the vast majority of users, there's really no point in ever calling those methods directly (the `NetworkManager` handles it). It's only useful if wrapping transports outside of NGO. (#3890)
38+
2239
### Removed
2340
- Removed un-needed exceptions on `NetworkObject.cs`. (#3867)
2441

@@ -28,9 +45,6 @@ Additional documentation and release notes are available at [Multiplayer Documen
2845
- NestedNetworkVariables initialized with no value no longer throw an error. (#3891)
2946
- Fixed `NetworkShow` behavior when it is called twice. (#3867)
3047

31-
### Security
32-
33-
3448
### Obsolete
3549
- `NotListeningException` is now marked as obsolete as it is no longer used internally. (#3867)
3650

com.unity.netcode.gameobjects/Documentation~/TableOfContents.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
* [Distributed authority WebGL quickstart](learn/distributed-authority-webgl.md)
88
* [Networking concepts](networking-concepts.md)
99
* [Authority](terms-concepts/authority.md)
10-
* [Ownership](terms-concepts/ownership.md)
1110
* [Network topologies](network-topologies.md)
1211
* [Network topologies](terms-concepts/network-topologies.md)
1312
* [Client-server](terms-concepts/client-server.md)
1413
* [Listen server host architecture](learn/listenserverhostarchitecture.md)
1514
* [Distributed authority topologies](terms-concepts/distributed-authority.md)
15+
* [Ownership](terms-concepts/ownership.md)
1616
* [Configuration](configuration.md)
1717
* [Configuring connections](configure-connections.md)
1818
* [Connection approval](basics/connection-approval.md)
@@ -23,9 +23,11 @@
2323
* [Network components](network-components.md)
2424
* [Core components](components/core/corecomponents.md)
2525
* [NetworkObject](components/core/networkobject.md)
26+
* [NetworkObject ownership](components/core/networkobject-ownership.md)
2627
* [NetworkObject parenting](advanced-topics/networkobject-parenting.md)
2728
* [NetworkBehaviour](components/core/networkbehaviour.md)
2829
* [Synchronizing & Order of Operations](components/core/networkbehaviour-synchronize.md)
30+
* [NetworkBehaviour ownership](components/core/networkbehaviour-ownership.md)
2931
* [NetworkManager](components/core/networkmanager.md)
3032
* [PlayerObjects and player prefabs](components/core/playerobjects.md)
3133
* [Helper Components](components/helper/helpercomponents.md)

com.unity.netcode.gameobjects/Documentation~/advanced-topics/message-system/rpc-compatibility.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ However, the RPC signature hash doesn't change when the names of the parameters
3636

3737
When the RPC signature changes, it directs to a different invocation code path that has different serialization code. This means that the RPC method with the new signature doesn't invoke previous versions of that RPC method (for example, an RPC method from an older build).
3838

39-
| Compatibility | <i class="fp-check"></i> | Description |
40-
| -- | :--: | -- |
41-
| Cross-Build Compatibility | <i class="fp-check"></i> | As long as the RPC method signature is kept the same, it will be compatible between different builds. |
42-
| Cross-Version Compatibility | <i class="fp-check"></i> | As long as the RPC method signature is kept the same, it will be compatible between different versions. |
43-
| Cross-Project Compatibility | <i class="fp-x"></i> | The exact same RPC method signature can be defined in different projects. This is because the project name or project-specific token isn't part of RPC signature. Cross-project RPC methods aren't compatible with each other. |
39+
| Compatibility | | Description |
40+
| -- | -- | -- |
41+
| Cross-Build Compatibility | **Yes** | As long as the RPC method signature is kept the same, it will be compatible between different builds. |
42+
| Cross-Version Compatibility | **Yes** | As long as the RPC method signature is kept the same, it will be compatible between different versions. |
43+
| Cross-Project Compatibility | No | The exact same RPC method signature can be defined in different projects. This is because the project name or project-specific token isn't part of RPC signature. Cross-project RPC methods aren't compatible with each other. |
4444

4545
## Deprecation of return values
4646

com.unity.netcode.gameobjects/Documentation~/advanced-topics/networkobject-parenting.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# NetworkObject parenting
22

3-
### Overview
3+
## Overview
44

5-
If you aren't completely familiar with transform parenting in Unity, then it's highly recommended to [review over the existing Unity documentation](https://docs.unity3d.com/Manual/class-Transform.html) before reading further to properly synchronize all connected clients with any change in a GameObject component's transform parented status, Netcode for GameObjects requires that the parent and child GameObject components have NetworkObject components attached to them.
5+
If you aren't familiar with transform parenting in Unity, then it's recommended that you [review the existing Unity documentation](https://docs.unity3d.com/Manual/class-Transform.html) before reading further. To properly synchronize all connected clients with any change in a GameObject component's transform parented status, Netcode for GameObjects requires that the parent and child GameObject components have NetworkObject components attached to them. Otherwise, you can use the [AttachableBehaviour](../components/helper/attachablebehaviour.md) and [AttachableNode](../components/helper/attachablenode.md) helper components to synchronize other types of parenting.
66

7-
### Parenting rules
7+
## Parenting rules
88

99
- Setting the parent of a child's `Transform` directly (that is, `transform.parent = childTransform;`) always uses the default `WorldPositionStays` value of `true`.
1010
- It's recommended to always use the `NetworkObject.TrySetParent` method when parenting if you plan on changing the `WorldPositionStays` default value.
1111
- Likewise, it's also recommended to use the `NetworkObject.TryRemoveParent` method to remove a parent from a child.
12-
- When a server parents a spawned NetworkObject component under another spawned NetworkObject component during a Netcode game session this parent child relationship replicates across the network to all connected and future late joining clients.
12+
- When an [authority](../terms-concepts/authority.md) parents a spawned NetworkObject component under another spawned NetworkObject component during a Netcode game session, this parent-child relationship replicates across the network to all connected and future late-joining clients.
1313
- If, while editing a scene, you place an in-scene placed NetworkObject component under a GameObject component that doesn't have a NetworkObject component attached to it, Netcode for GameObjects preserves that parenting relationship.
1414
- During runtime, this parent-child hierarchy remains true unless the user code removes the GameObject parent from the child NetworkObject component.
1515
- **Note**: Once removed, Netcode for GameObjects won't allow you to re-parent the NetworkObject component back under the same or another GameObject component that with no NetworkObject component attached to it.
@@ -35,15 +35,26 @@ If you aren't completely familiar with transform parenting in Unity, then it's h
3535
virtual void OnNetworkObjectParentChanged(NetworkObject parentNetworkObject) { }
3636
```
3737

38-
> [!NOTE] Multi-generation children and scale
38+
> [!NOTE]
39+
> Multi-generation children and scale
3940
> If you are dealing with more than one generation of nested children where each parent and child have scale values other than `Vector3.one`, then mixing the `WorldPositionStays` value when parenting and removing a parent will impact how the final scale is calculated! If you want to keep the same values before parenting when removing a parent from a child, then you need to use the same `WorldPositionStays` value used when the child was parented.
4041
41-
### Only a server (or a host) can parent NetworkObjects
42+
### Who can parent NetworkObjects
43+
44+
#### Under a spawned NetworkObject
45+
46+
The [owner](../terms-concepts/ownership.md) of a NetworkObject can always parent that NetworkObject under any other spawned NetworkObject. This works regardless of who owns the other NetworkObject.
47+
48+
#### Under other GameObjects
49+
50+
By default, only the [authority](../terms-concepts/authority.md) of a NetworkObject can parent a NetworkObject under a non-networked object. This means in a client-server game, only the server (or host) can control NetworkObject component parenting. In a distributed authority game the [owner](../terms-concepts/ownership.md) of the object can always parent the object.
51+
52+
To allow the [owner](../terms-concepts/ownership.md) to parent their owned NetworkObject in a client-server game, use the [`NetworkObject.AllowOwnerToParent`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkObject.html#Unity_Netcode_NetworkObject_AllowOwnerToParent) property.
4253

43-
Similar to [Ownership](../basics/networkobject#ownership), only the server (or host) can control NetworkObject component parenting.
54+
![image](../images/networkobject/allowOwnerToParent.png)
4455

4556
> [!NOTE]
46-
> If you run into a situation where your client must trigger parenting a NetworkObject component, one solution is for the client to send an RPC to the server. Upon receiving the RPC message, the server then handles parenting the NetworkObject component.
57+
> If you run into a situation where your client must trigger parenting a NetworkObject component, one solution is for the client to send an RPC to the authority. Upon receiving the RPC message, the authority then handles parenting the NetworkObject component.
4758
4859
### Only parent under a NetworkObject Or nothing (root or null)
4960

com.unity.netcode.gameobjects/Documentation~/basics/object-spawning.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ When using a [server authoritative networking model](../terms-concepts/authority
3030

3131
To spawn a network prefab, you must first create an instance of the network prefab and then invoke the spawn method on the NetworkObject component of the instance you created. In most cases, you will want to keep the NetworkObject component attached to the root GameObject of the network prefab.
3232

33-
By default, a newly spawned network prefab instance is owned by the authority unless otherwise specified.
34-
35-
See [Ownership](networkobject.md#ownership) for more information.
33+
Refer to [NetworkObject ownership](../advanced-topics/networkobject-ownership.md) for more information.
3634

3735
The following is a basic example of how to spawn a network prefab instance:
3836

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# NetworkBehaviour ownership
2+
3+
Before reading these docs, ensure you understand the concepts of [ownership](../terms-concepts/ownership.md) and [NetworkObject ownership](./networkobject-ownership.md). It's also important to be familiar with the [NetworkBehaviour](./networkbehaviour.md)
4+
5+
The owner of each NetworkBehaviour in your game is decided by the owner of that NetworkBehaviour's NetworkObject. The NetworkObject is found as a property on the NetworkBehaviour: [`NetworkBehaviour.NetworkObject`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html#Unity_Netcode_NetworkBehaviour_NetworkObject).
6+
7+
## Helpful properties
8+
9+
> [!NOTE]
10+
> The following properties are only valid if the NetworkBehaviour has been spawned. Use [`NetworkBehaviour.IsSpawned`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html#Unity_Netcode_NetworkBehaviour_IsSpawned) to check the spawned status of the NetworkBehaviour
11+
12+
To identify whether the local client is the owner of a NetworkBehaviour, you can check the[`NetworkBehaviour.IsOwner`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html#Unity_Netcode_NetworkBehaviour_IsOwner) property.
13+
14+
To identify whether the server owns a NetworkBehaviour, you can check the [`NetworkBehaviour.IsOwnedByServer`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html#Unity_Netcode_NetworkBehaviour_IsOwnedByServer) property.
15+
16+
To identify whether the local client has authority of a NetworkBehaviour, you can check the[`NetworkBehaviour.HasAuthority`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html#Unity_Netcode_NetworkBehaviour_HasAuthority) property.
17+
18+
## Detecting ownership changes
19+
20+
There are three functions that can be implemented to detect ownership changes on a NetworkBehaviour. These functions are invoked in the order they are listed here.
21+
22+
### [OnLostOwnership](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html#Unity_Netcode_NetworkBehaviour_OnLostOwnership)
23+
24+
When using a [client-server network topology](../../terms-concepts/client-server.md) `OnLostOwnership` is invoked on both the server any time a connected client loses ownership of this NetworkBehaviour. It is also invoked on the game client who just lost ownership.
25+
26+
In a [distributed authority network topology](../../terms-concepts/distributed-authority.md) `OnLostOwnership` is invoked on all connected game clients.
27+
28+
```csharp
29+
void OnLostOwnership()
30+
{
31+
var newOwner = OwnerClientId;
32+
33+
// Take action on lost ownership here
34+
}
35+
```
36+
37+
### [OnGainedOwnership](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html#Unity_Netcode_NetworkBehaviour_OnGainedOwnership)
38+
39+
When using a client-server network topology `OnGainedOwnership` is invoked on the server any time ownership is gained. It is also be invoked on the game client who just gained ownership.
40+
41+
In a distributed authority network topology `OnGainedOwnership` is invoked on all connected game clients.
42+
43+
`OnGainedOwnership` is invoked after `OnLostOwnership`.
44+
45+
```csharp
46+
void OnGainedOwnership()
47+
{
48+
var newOwner = OwnerClientId;
49+
var newOwnerIsMe = IsOwner;
50+
51+
// Take action on ownership gain here
52+
}
53+
```
54+
55+
### [OnOwnershipChanged](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html#Unity_Netcode_NetworkBehaviour_OnOwnershipChanged_System_UInt64_System_UInt64_)
56+
57+
Whenever you want notification on any and all ownership changes, implement the `OnOwnershipChanged` method. `OnOwnershipChanged` is invoked on all connected game clients whenever the ownership of the NetworkBehaviour it is implemented on changes.
58+
59+
`OnOwnershipChanged` is invoked after `OnLostOwnership` and `OnGainedOwnership`.
60+
61+
```csharp
62+
void OnOwnershipChanged(ulong previousOwnerId, ulong currentOwnerId)
63+
{
64+
var newOwnerIsMe = IsOwner;
65+
66+
// Take action on ownership change here
67+
}
68+
```

com.unity.netcode.gameobjects/Documentation~/components/core/networkbehaviour.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NetworkBehaviour spawning and despawning
1+
# NetworkBehaviour
22

33
[NetworkBehaviour](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html) is an abstract class that derives from [MonoBehaviour](https://docs.unity3d.com/ScriptReference/MonoBehaviour.html) and is primarily used to create unique netcode or game logic. To replicate any netcode-aware properties or send and receive RPCs, a [GameObject](https://docs.unity3d.com/Manual/GameObjects.html) must have a [NetworkObject](networkobject.md) component and at least one NetworkBehaviour component.
44

@@ -38,6 +38,7 @@ The diagram above represents how the spawn process works for two NetworkBehaviou
3838
NetworkObjects go through three states during the spawn process:
3939

4040
**Spawn states**
41+
4142
- Prespawning: Before any netcode-related properties have been set.
4243
- Spawning: Netcode-related properties have been set.
4344
- Spawned: All NetworkBehaviour components have completed their spawn logic.
@@ -98,7 +99,7 @@ private void Update()
9899

99100
Alternatively, you can leverage the [NetworkUpdateLoop](../../advanced-topics/network-update-loop-system/index.md) system by making a NetworkBehaviour implement the `INetworkUpdateSystem` interface and register each instance for a specific `NetworkUpdateStage` during the `OnNetworkSpawn` or `OnNetworkPreSpawn` invocations, and then use your own script logic to determine which instance should be updating.
100101

101-
This can be useful when you want only the owner, authority, or non-authority to be updating and can help to remove checks like the above. It can also reduce the performance cost of all instances that do not register for the update stage (depending upon how many instances are spawned).
102+
This can be useful when you want only the [owner](../../terms-concepts/ownership.md), [authority](../../terms-concepts/authority.md), or non-authority to be updating and can help to remove checks like the above. It can also reduce the performance cost of all instances that do not register for the update stage (depending upon how many instances are spawned).
102103

103104
### Dynamically spawned NetworkObjects
104105

@@ -189,4 +190,4 @@ Similar to the [spawn process and invocation order section above](#spawn-process
189190
## Additional resources
190191

191192
- [NetworkObjects](networkobject.md)
192-
- [NetworkBehaviour synchronization](networkbehaviour-synchronize.md)
193+
- [NetworkBehaviour synchronization](networkbehaviour-synchronize.md)

0 commit comments

Comments
 (0)