Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Minimum Players

Discussion in 'Multiplayer' started by LukasO, Jul 15, 2015.

  1. LukasO

    LukasO

    Joined:
    May 23, 2013
    Posts:
    115
    Any way of forcing a Network lobby to wait for a minimum amount of players before it'll start?

    Thanks,

    Lukas
     
    danilo_lima likes this.
  2. danilo_lima

    danilo_lima

    Joined:
    Mar 25, 2013
    Posts:
    2
    I want know this too.
     
  3. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    this is in for 5.2. along with a callback to allow custom handling when all players are ready.
     
  4. LukasO

    LukasO

    Joined:
    May 23, 2013
    Posts:
    115
    Thanks for the reply. Any sort of estimation how long it'll be til we receive 5.2? It would be useful as well if we could have a mechanism on the server to force a game to start regardless of whether players are ready if too much time has passed.
     
  5. Swiggies

    Swiggies

    Joined:
    Mar 28, 2014
    Posts:
    11
    You could very easily write a function so that every time someone connects it adds to a variable (and minus 1 every time someone disconnects) and compare it to your desired minimum players.


    Code (CSharp):
    1.  
    2. int minimumPlayers = 4;
    3. int currentPlayers = 0;
    4.  
    5. //Called in OnServerConnect or OnServerDisconnect
    6. public void PlayerCheck (int x){
    7.    //x = 1 on connect and -1 on disconnect
    8.    currentPlayer += 0;
    9.    if(currentPlayers == minimumPlayers){
    10.       StartGame();
    11.    }
    12. }
    13.  
    This could probably be put in a bool function but that's how I do it.
     
  6. LukasO

    LukasO

    Joined:
    May 23, 2013
    Posts:
    115
    I don't think that works as if a client calls SendReadyToBeginMessage(), the server seems to automatically check that all players are ready and then start the game. As far as I'm aware you can't override that behaviour.
     
  7. OldUnityFool

    OldUnityFool

    Joined:
    Feb 27, 2015
    Posts:
    25