Skip to content

Commit 7422c91

Browse files
EmandMjabbacakes
andauthored
chore: Ownership docs (#3694)
* Add initial ownership docs page * Doc review * Adding ownership request table * Removing old ownership page * Remove unclear sentence --------- Co-authored-by: Amy Reeve <[email protected]>
1 parent 06118b8 commit 7422c91

File tree

9 files changed

+243
-156
lines changed

9 files changed

+243
-156
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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)
1011
* [Network topologies](network-topologies.md)
1112
* [Network topologies](terms-concepts/network-topologies.md)
1213
* [Client-server](terms-concepts/client-server.md)
@@ -33,9 +34,6 @@
3334
* [NetworkAnimator](components/helper/networkanimator.md)
3435
* [NetworkTransform](components/helper/networktransform.md)
3536
* [Physics](advanced-topics/physics.md)
36-
* [Ownership and authority](ownership-authority.md)
37-
* [Understanding ownership and authority](basics/ownership.md)
38-
* [Ownership race conditions](basics/race-conditions.md)
3937
* [Spawning and despawning](spawn-despawn.md)
4038
* [Object spawning](basics/object-spawning.md)
4139
* [Network prefab handler](advanced-topics/network-prefab-handler.md)

com.unity.netcode.gameobjects/Documentation~/basics/ownership.md

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

com.unity.netcode.gameobjects/Documentation~/basics/race-conditions.md

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

com.unity.netcode.gameobjects/Documentation~/networking-concepts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ Understand the networking concepts that underpin Netcode for GameObjects.
55
| **Topic** | **Description** |
66
| :------------------------------ | :------------------------------- |
77
| **[Authority](terms-concepts/authority.md)** | Multiplayer games are games that are played between many different game instances. Each game instance has their own copy of the game world and behaviors within that game world. To have a shared game experience, each networked object is required to have an **authority**. |
8+
| **[Ownership](terms-concepts/ownership.md)** | Understand how ownership works in Netcode for GameObjects as a precursor to [authority](terms-concepts/authority.md). |
89
| **[Network topologies](network-topologies.md)** | Understand and decide which network topology to use in your project. |

com.unity.netcode.gameobjects/Documentation~/ownership-authority.md

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

com.unity.netcode.gameobjects/Documentation~/terms-concepts/authority.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,52 @@ Netcode for GameObjects provides two authority models: [server authority](#serve
1414

1515
The server authority model has a single game instance that is defined as the server. That game instance is responsible for running the main simulation and managing all aspects of running the networked game. Server authority is the authority model used for [client-server games](client-server.md).
1616

17-
The server authority model has the strength of providing a centralized authority to manage any potential game state conflicts. This allows the implementation of systems such as game state rollback and competitive client prediction. However, this can come at the cost of adding latencies, because all state changes must be sent to the server game instance, processed, and then sent out to other game instances.
17+
The server authority model has the strength of providing a centralized authority to manage any potential game state conflicts. This allows the implementation of systems such as game state rollback and competitive client prediction. However, this can come at the expense of adding latencies, because all state changes must be sent to the server game instance, processed, and then sent out to other game instances.
1818

1919
Server authority games can also be resource intensive. The server runs the simulation for the entire game world, and so the server needs to be powerful enough to handle the simulation and networking of all connected game clients. This resource requirement can become expensive.
2020

2121
Server authority is primarily used by performance-sensitive games, such as first-person shooters, or competitive games where having a central server authority is necessary to minimize cheating and the effects of bad actors.
2222

2323
### Distributed authority
2424

25-
The distributed authority model shares authority between game instances. Each game instance is the authority for a subdivision of the networked objects in the game and is responsible for running the simulation for their subdivision of objects. Updates are shared from other game instances for the rest of the simulation.
25+
The [distributed authority model](distributed-authority.md) shares authority between game instances. Each game instance is the authority for a subdivision of the networked objects in the game and is responsible for running the simulation for their subdivision of objects. Updates are shared from other game instances for the rest of the simulation.
2626

27-
The authority of each networked object is responsible for simulating the behavior and managing any aspects of running the networked game that relate to the objects it is the authority of.
27+
The authority of each networked object is responsible for simulating the behavior and managing any aspects of running the networked game that relate to the objects it's the authority of.
2828

29-
Because distributed authority games share the simulation between each connected client, they are less resource intensive. Each machine connected to the game processes a subdivision of the simulation, so no single machine needs to have the capacity to process the entire simulation. This results in a multiplayer game experience that can run on cheaper machines and is less resource intensive.
29+
Because distributed authority games share the simulation between each connected client, they're less resource intensive. Each machine connected to the game processes a subdivision of the simulation, so no single machine needs to have the capacity to process the entire simulation. This results in a multiplayer game experience that can run on cheaper machines and is less resource intensive.
3030

31-
The distributed authority model is the authority model used for [distributed authority games](distributed-authority.md).
31+
## Checking for authority
32+
33+
The `HasAuthority` property, which is available on both NetworkObjects and NetworkBehaviours, is session-mode agnostic and works in both distributed authority and client-server contexts. It's recommended to use `HasAuthority` whenever you're working with individual objects, regardless of whether you're using a distributed authority or client-server topology.
34+
35+
```csharp
36+
public class MonsterAI : NetworkBehaviour
37+
{
38+
public override void OnNetworkSpawn()
39+
{
40+
if (!HasAuthority)
41+
{
42+
return;
43+
}
44+
// Authority monster init script here
45+
base.OnNetworkSpawn();
46+
}
47+
48+
private void Update()
49+
{
50+
if (!IsSpawned || !HasAuthority)
51+
{
52+
return;
53+
}
54+
// Authority updates monster AI here
55+
}
56+
}
57+
```
58+
59+
Using distributed authority with Netcode for GameObjects requires a shift in the understanding of authority: instead of authority belonging to the server in all cases, it belongs to whichever client instance currently has authority. This necessitates a shift away from using local, non-replicated properties to store pertinent states; instead, [NetworkVariables](../basics/networkvariable.md) should be used to keep states synchronized and saved when all clients disconnect from a session or ownership is transferred to another client.
60+
61+
Distributed authority supports all built-in NetworkVariable data types. Because there's no concept of an authoritative server in a distributed authority session, all NetworkVariables are automatically configured with owner write and everyone read permissions.
62+
63+
## Additional resources
64+
65+
- [Ownership](ownership.md)

0 commit comments

Comments
 (0)