Skip to main content

Limiting the maximum number of players

Netcode for Gameobjects (Netcode) provides a way to implement a connection approval delegate that can reject incoming connections based on custom logic. ​

Boss Room provides an example of such delegate

Assets/BossRoom/Scripts/Server/Net/ServerGameNetPortal.cs
loading...
See full example on GitHub

​ The 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_ClientData.Count >= CharSelectData.k_MaxLobbyPlayers )
{
gameReturnStatus = ConnectStatus.ServerFull;
}

SUIBJECT TO CHANGE:

​ In connection approval delegate Netcode does not support an ability to send anything more than a boolean back. Boss Room demonstrates a way to provide meaningful error code to the client by invoking a client RPC in the same channel that Netcode uses for its connection callback.