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

Updating Maxplayers and Playscene at Runtime

Discussion in 'Multiplayer' started by Jwolf, Jun 15, 2015.

  1. Jwolf

    Jwolf

    Joined:
    Sep 8, 2013
    Posts:
    16
    I am starting from the NetworkStarter project to get a better handle on the new match making service.

    I have add buttons to the Match Maker Canvas to allow a change in the NetworkLobbyManager play scene. It also changes the max number of players in the lobby to match the new play scene. This happens before any connection occurs.

    The code is working fine when the host is created through the Unity Editor, but does not work when the host is a stand alone build. I just updated Unity to 5.1 p1 and still have the same problem.

    Below is the function called to switch the play scene and the max players. The function is in the GuiLobbyControllers script.

    What am I missing?

    Code (CSharp):
    1. public void OnGUISetMapNum()
    2.     {
    3.         var hooks = canvas.GetComponent<MatchMakerHooks>();
    4.         if (hooks == null)
    5.             return;
    6.  
    7.         int sceneNum;
    8.         sceneNum = hooks.mapNum;
    9.         string sceneName;
    10.         int maxPlayers;
    11.  
    12.         switch (sceneNum)
    13.         {
    14.             case 1:
    15.                 sceneName = GuiLobbyManager.s_Singleton.scene1.name;
    16.                 maxPlayers = GuiLobbyManager.s_Singleton.maxPlayerS1;
    17.                 break;
    18.             case 2:
    19.                 sceneName = GuiLobbyManager.s_Singleton.scene2.name;
    20.                 maxPlayers = GuiLobbyManager.s_Singleton.maxPlayersS2;
    21.                 break;
    22.             default:
    23.                 sceneName = GuiLobbyManager.s_Singleton.scene2.name;
    24.                 maxPlayers = GuiLobbyManager.s_Singleton.maxPlayersS2;
    25.                 break;
    26.         }
    27.         GuiLobbyManager.s_Singleton.playScene = sceneName;
    28.         GuiLobbyManager.s_Singleton.maxPlayers = maxPlayers;
    29.     }
    30.    
     
    Last edited: Jun 15, 2015
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    how does it not work? Are the members not being set?
     
  3. Jwolf

    Jwolf

    Joined:
    Sep 8, 2013
    Posts:
    16
    Guess that's a good detail to add :)

    Yes, the max number of players and the playscene are not changed, but stay at the default values set in the inspector at build time.
     
  4. webgovernor

    webgovernor

    Joined:
    Feb 10, 2013
    Posts:
    18
    This is also the case for me on 5.3.1p1.

    Immediately before hosting a game, the lobby maxPlayers is set to 5 on the host. I have verified this.

    All connected clients, aside from the host, see whatever was set in the inspector (this case, 4).

    Any update on this?
     
  5. webgovernor

    webgovernor

    Joined:
    Feb 10, 2013
    Posts:
    18
    Still an issue in 5.3.1p3.

    My work-around involves using SyncVars on a NetworkBehavior attached to the lobbyPlayerPrefab instance, and I assign the proper values to the NetworkBehavior in OnLobbyServerCreateLobbyPlayer. The UI on each client then uses values from the NetworkBehavior on their lobbyPlayerPrefab instance.

    Still seems like a bug, or something that needs documentation, but it's manageable.