| id | title | created | updated |
|---|---|---|---|
max-players |
Limiting the maximum number of players |
2023-01-24 18:08:36 -0600 |
2023-01-24 18:59:55 -0600 |
Netcode for GameObjects provides a way to customize the connection approval process that can reject incoming connections based on any number of user-specific reasons.
Boss Room provides one example of how to handle limiting the number of players through the connection approval process:
https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/v2.2.0/Assets/Scripts/ConnectionManagement/ConnectionState/HostingState.csThe code below shows an example of an over-capacity check that would prevent more than a certain pre-defined number of players from connecting.
if( m_Portal.NetManager.ConnectedClientsIds.Count >= CharSelectData.k_MaxLobbyPlayers )
{
return ConnectStatus.ServerFull;
}:::tip
In connection approval delegate, Netcode for GameObjects doesn't support sending anything more than a Boolean back.
Boss Room shows a way to offer meaningful error code to the client by invoking a client RPC in the same channel that Netcode for GameObjects uses for its connection callback.
:::
When using Relay, ensure the maximum number of peer connections allowed by the host satisfies the logic implemented in the connection approval delegate.