Skip to content

Commit cc60ac4

Browse files
committed
more ownerhsip docs (we were missing lots)
1 parent a049f82 commit cc60ac4

File tree

17 files changed

+391
-200
lines changed

17 files changed

+391
-200
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
* [Network components](network-components.md)
2424
* [Core components](components/core/corecomponents.md)
2525
* [NetworkObject](components/core/networkobject.md)
26-
* [NetworkObject ownership](advanced-topics/networkobject-ownership.md)
26+
* [NetworkObject ownership](components/core/networkobject-ownership.md)
2727
* [NetworkObject parenting](advanced-topics/networkobject-parenting.md)
2828
* [NetworkBehaviour](components/core/networkbehaviour.md)
2929
* [Synchronizing & Order of Operations](components/core/networkbehaviour-synchronize.md)
30+
* [NetworkBehaviour ownership](components/core/networkbehaviour-ownership.md)
3031
* [NetworkManager](components/core/networkmanager.md)
3132
* [PlayerObjects and player prefabs](components/core/playerobjects.md)
3233
* [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-ownership.md

Lines changed: 0 additions & 164 deletions
This file was deleted.

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ 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
4142
### Who can parent NetworkObjects
4243

43-
By default, only the [authority](../terms-concepts/authority.md) of an object can change the parenting of the 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 of the object can always parent the object.
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.
4451

45-
To allow the [owner](../terms-concepts/ownership.md) to parent their owned object 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.
52+
To allow the owner to parent their owned object 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.
4653

4754
![image](../images/networkobject/allowOwnerToParent.png)
4855

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +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-
See [NetworkObject ownership](../advanced-topics/networkobject-ownership.md) for more information.
33+
See [NetworkObject ownership](../components/core/networkobject-ownership.md) for more information.
3434

3535
The following is a basic example of how to spawn a network prefab instance:
3636

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 see if 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 see if 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 see if 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+
```

0 commit comments

Comments
 (0)