docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Limiting the maximum number of players

    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.

    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_Portal.NetManager.ConnectedClientsIds.Count >= CharSelectData.k_MaxLobbyPlayers )
    {
        return ConnectStatus.ServerFull;
    }
    

    [!NOTE]​ In connection approval delegate, Netcode for GameObjects doesn't support sending anything more than a Boolean back.

    When using Relay, ensure the maximum number of peer connections allowed by the host satisfies the logic implemented in the connection approval delegate.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)