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
chore: Add DA ConnectionApprovalCallback warnings (#3658)
## Purpose of this PR
[A post on the discussions
board](https://discussions.unity.com/t/connection-approval-callback-not-firing/1682730)
pointed out that we don't have any information around the
`ConnectionApprovalCallback` indicating that it won't work with
distributed authority.
This PR:
- Adds a note on the connection approval docs page to indicate that it
doesn't work with DA
- Updates the NetworkManager docs page to be up-to-date with DA
- Adds a developer log level warning on ConnectionApproval when using DA
that the ConnectionApproval setting is not valid (might not be the best
location, maybe better in `StartClient`?)
- Updates the NetworkTransformOwnershipTests to be DA friendly (needed
for manual testing of this feature)
### Jira ticket
n/a
### Changelog
[//]: # (updated with all public facing changes - API changes, UI/UX
changes, behaviour changes, bug fixes. Remove if not relevant.)
- Added: A warning when
`NetworkManager.NetworkConfig.ConnectionApproval` is set in a DA
context.
## Documentation
- Includes edits to existing public API documentation.
## Docs screenshots
### Connection Approval:
<img width="737" height="145" alt="Screenshot 2025-09-09 at 11 37 58 AM"
src="https://github.com/user-attachments/assets/97f321cf-a69b-46b1-b4bb-c2e5b14a214c"
/>
### NetworkConfig settings
<img width="726" height="750" alt="Screenshot 2025-09-09 at 11 37 48 AM"
src="https://github.com/user-attachments/assets/6e55db7a-c51e-4083-9562-fc93db8ff08a"
/>
### NetworkManager start
<img width="722" height="646" alt="Screenshot 2025-09-09 at 11 37 36 AM"
src="https://github.com/user-attachments/assets/5e7a81d7-7108-40b2-81da-f2986513e2f5"
/>
---------
Co-authored-by: Noel Stephens <[email protected]>
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Documentation~/basics/connection-approval.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,8 @@
1
1
# Connection approval
2
2
3
+
> [!NOTE]
4
+
>Connection approval is not currently supported when using a [distributed authority topology](../terms-concepts/distributed-authority.md).
5
+
3
6
With every new connection, Netcode for GameObjects performs a handshake in addition to handshakes done by the transport. This ensures that the NetworkConfig on the client matches the server's NetworkConfig. You can enable ConnectionApproval in the NetworkManager or via code by setting `NetworkManager.NetworkConfig.ConnectionApproval` to `true`. Connection approval allows you to decide, on a per connection basis, whether to allow a connection. You can also use connection approval to specify the player Prefab to create, allowing you to override the default NetworkManager-defined player Prefab on a per player basis.
4
7
5
8
When you set the ConnectionApproval property of the NetworkManager to true, Netcode for GameObjects checks to make sure the `NetworkManager.ConnectionApprovalCallback` has been assigned. If assigned, the connection approval process is used for connecting clients to decide whether to allow a connection or deny it. If you don't assign the `NetworkManager.ConnectionApprovalCallback` (even with the `NetworkManager.ConnectionApprovalCallback` set to `true`), Netcode for GameObjects uses basic authentication for the user, which automatically authorizes and assigns the default player Prefab.
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Documentation~/components/core/networkmanager.md
+36-14Lines changed: 36 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,15 @@ The NetworkManager is a required Netcode for GameObjects component that has all
5
5
## NetworkManager Inspector properties
6
6
7
7
-**LogLevel**: Sets the network logging level
8
-
-**PlayerPrefab**: When a Prefab is assigned, the Prefab will be instantiated as the player object and assigned to the newly connected and authorized client. For more information about player prefabs, refer to [Player NetworkObjects](networkobject.md#player-networkobjects).
8
+
-**PlayerPrefab**: When a Prefab is assigned, the Prefab will be instantiated as the player object. For more information about player prefabs, refer to [Player NetworkObjects](networkobject.md#player-networkobjects).
9
9
-**NetworkPrefabs**: Where you register your network prefabs. You can also create a single network Prefab override per registered network Prefab here.
10
10
-**Protocol Version**: Set this value to help distinguish between builds when the most current build has new assets that can cause issues with older builds connecting.
11
-
-**Network Transport**: Where your network specific settings and transport type is set. This field accepts any INetworkTransport implementation. However, unless you have unique transport specific needs UnityTransport is the recommended transport to use with Netcode for GameObjects.
11
+
-**Network Transport**: Where your network specific settings and transport type is set. When using a [client-server topology](../../terms-concepts/client-server.md), This field accepts any INetworkTransport implementation. However, unless you have unique transport specific needs UnityTransport is the recommended transport to use with Netcode for GameObjects. For a [distributed authority topology](../../terms-concepts/distributed-authority.md), refer to the [distributed authority quickstart](../../learn/distributed-authority-quick-start.md).
12
12
-**Tick Rate**: This value controls the network tick update rate.
13
13
-**Ensure Network Variable Length Safety**: (Increases cpu processing and bandwidth) When this property is checked, Netcode for GameObjects will prevent user code from writing past the boundaries of a NetworkVariable.
14
-
-**Connection Approval**: This enables [connection approval](../../basics/connection-approval.md) when this is checked and the `NetworkManager.ConnectionApprovalCallback` is assigned.
14
+
-**Connection Approval**: This enables [connection approval](../../basics/connection-approval.md) when this is checked and the `NetworkManager.ConnectionApprovalCallback` is assigned. This setting does nothing when using a [distributed authority topology](../../terms-concepts/distributed-authority.md).
15
15
-**Client Connection Buffer Timeout**: This value sets the amount of time that has to pass for a connecting client to complete the connection approval process. If the time specified is exceeded the connecting client will be disconnected.
16
-
-**Force Same Prefabs**: When checked it will always verify that connecting clients have the same registered network prefabs as the server. When not checked, Netcode for GameObjects will ignore any differences.
16
+
-**Force Same Prefabs**: When checked it will always verify that connecting clients have the same registered network prefabs as the [authority game client](../../terms-concepts/authority.md). When not checked, Netcode for GameObjects will ignore any differences.
17
17
-**Recycle Network Ids**: When checked this will re-use previously assigned `NetworkObject.NetworkObjectIds` after the specified period of time.
18
18
-**Network Id Recycle Delay**: The time it takes for a previously assigned but currently unassigned identifier to be available for use.
19
19
-**Enable Scene Management**: When checked, Netcode for GameObjects will handle scene management and client synchronization for you. When not checked, you will have to create your own scene management scripts and handle client synchronization.
@@ -34,12 +34,32 @@ NetworkManager is also where you can find references to other Netcode related ma
34
34
35
35
## Starting a server, host, or client
36
36
37
-
To perform any netcode-related action that involves sending messages, you must first have a server started and listening for connections with at least one client (_a server can send RPCs to itself when running as a host_) that is connected. To accomplish this, you must first start your NetworkManager as a server, host, or client. There are three NetworkManager methods you can invoke to accomplish this:
37
+
To perform any netcode-related action that involves sending messages you must first start your NetworkManager. Your NetworkManager can be started as either a server, host, or a client.
38
+
39
+
### Starting as a server
40
+
41
+
A server can't act as a local client. When starting as a server, no messages will be sent until at least one other client is connected. A server can only be used with a [client-server topology](../../terms-concepts/client-server.md).
42
+
43
+
```csharp
44
+
NetworkManager.Singleton.StartServer();
45
+
```
46
+
47
+
### Starting as a host
48
+
49
+
A host is both a server and a client (that is, has local client). A host can send RPCs to itself, and so can start sending some messages before another client is connected. A host can only be used with a [client-server topology](../../terms-concepts/client-server.md).
50
+
51
+
```csharp
52
+
NetworkManager.Singleton.StartHost();
53
+
```
54
+
55
+
### Starting as a client
56
+
57
+
This is the most general option for the NetworkManager. Starting as a client starts a single game client that will either connect to the server or host (under a client-server topology) or connect to a distributed authority session (under a distributed authority topology).
58
+
59
+
When using the distributed authority topology, the first client who joins and connects to the session will become the [session owner](../../terms-concepts/distributed-authority.md#session-ownership)
38
60
39
61
```csharp
40
-
NetworkManager.Singleton.StartServer(); // Starts the NetworkManager as just a server (that is, no local client).
41
-
NetworkManager.Singleton.StartHost(); // Starts the NetworkManager as both a server and a client (that is, has local client)
42
-
NetworkManager.Singleton.StartClient(); // Starts the NetworkManager as just a client.
62
+
NetworkManager.Singleton.StartClient();
43
63
```
44
64
45
65
> [!NOTE]
@@ -56,7 +76,8 @@ When starting a client, the NetworkManager uses the IP and the Port provided in
56
76
57
77
The below examples use [Unity Transport](https://docs.unity3d.com/Packages/com.unity.transport@latest?subfolder=/manual/index.html) to show a few ways you can gain access to the `UnityTransport` component via the `NetworkManager.Singleton` to configure your project's network settings programmatically:
58
78
59
-
If you are only setting the IP address and port number, then you can use the `UnityTransport.SetConnectionData` method:
79
+
If you are only setting the IP address and port number, then you can use the `UnityTransport.SetConnectionData` method. This will return a [`ConnectionAddressData`**struct**](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/11922a0bc100a1615c541aa7298c47d253b74937/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs#L239-L286), holding this info. You are strongly advised to use the `SetConnectionData` method to update this info.
If you are using the same code block to configure both your server and your client and you want to configure your server to listen to all IP addresses assigned to it, then you can also pass a 'listen address' of "0.0.0.0" to the `SetConnectionData` method, like so:
> Using an IP address of 0.0.0.0 for the server listen address will make a server or host listen on all IP addresses assigned to the local system. This can be particularly helpful if you are testing a client instance on the same system as well as one or more client instances connecting from other systems on your local area network. Another scenario is while developing and debugging you might sometimes test local client instances on the same system and sometimes test client instances running on external systems.
78
100
79
-
It is possible to access the current connection data at runtime, via `NetworkManager.Singleton.GetComponent<UnityTransport>().ConnectionData`. This will return a [`ConnectionAddressData`**struct**](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/11922a0bc100a1615c541aa7298c47d253b74937/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs#L239-L286), holding this info. You are strongly advised to use the `SetConnectionData` method to update this info.
80
-
81
101
If you are using Unity Relay to handle connections, however, **don't use `SetConnectionData`**. The host should call [`SetHostRelayData`](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/11922a0bc100a1615c541aa7298c47d253b74937/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs#L575), and clients should call [`SetClientRelayData`](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/11922a0bc100a1615c541aa7298c47d253b74937/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs#L588). Attempting to join a **Relay**-hosted game via entering IP/port number (via `SetConnectionData`) **won't work**.
82
102
83
-
84
103
[More information about Netcode for GameObjects Transports](../../advanced-topics/transports.md)
Both the client and the server can subscribe to the `NetworkManager.OnClientDisconnectCallback` event to be notified when a client is disconnected.
158
+
Subscribe to the `NetworkManager.OnClientDisconnectCallback` event to receive notifications when a client is disconnected.
140
159
141
160
**When disconnect notifications are triggered:**
142
-
- Clients are notified when they're disconnected by the server.
161
+
162
+
- Clients are notified when they're disconnected by the server or from the distributed authority session.
143
163
- The server is notified when any client disconnects from the server, whether the server disconnects the client or the client disconnects itself.
144
164
- Both the server and clients are notified when their network connection is unexpectedly disconnected (network interruption).
145
165
146
166
**Client notification identifiers**
167
+
147
168
- On the server-side, the client identifier parameter is the identifier of the client that disconnects.
148
169
- On the client-side, the client identifier parameter is the identifier assigned to the client.
149
170
-_The exception to this is when a client is disconnected before its connection is approved._
150
171
151
172
You can also use the `NetworkManager.OnServerStopped` and `NetworkManager.OnClientStopped` callbacks to get local notifications when the server or client stops respectively.
152
173
153
174
### Connection notification manager example
175
+
154
176
Below is one example of how you can provide client connect and disconnect notifications to any type of NetworkBehaviour or MonoBehaviour derived component.
NetworkLog.LogWarning($"{nameof(NetworkConfig.ConnectionApproval)} is enabled but is not supported when using a distributed authority topology. The {nameof(NetworkManager.ConnectionApprovalCallback)} will not be invoked.");
0 commit comments