Search Unity

Unity Multiplayer [SOLVED] Error When Creating Multiplayer Lobby

Discussion in 'Multiplayer' started by Tetra, Jun 2, 2016.

  1. Tetra

    Tetra

    Joined:
    May 22, 2013
    Posts:
    29
    Hello!

    Not sure if this is the right place to post this, as I am trying to create my own GUI for the NetworkLobbyManager in Unity 5.4 Beta. Right now, I'm mostly having a hard time figuring out what code I need to start the MatchMaker Lobby. I've tried looking through documentation and through examples by others, but things are a mess since the Networking code has been simplified since 5.3. Here's some code that I was trying out. I can't seem to get any lobbies working. What am I missing? Is there somewhere other than the documentation that could provide me with more clear directions?

    Thanks in advance for any help that you can provide.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Networking;
    4. using UnityEngine.UI;
    5. using System.Collections;
    6.  
    7. public class MainMenuBehavior : MonoBehaviour
    8. {
    9.    public NetworkLobbyManager mgr;
    10.  
    11.    public GameObject MainMenuPanel;
    12.    public GameObject CreateGamePanel;
    13.    public GameObject JoinGamePanel;
    14.    public GameObject SettingsPanel;
    15.    public GameObject CreditsPanel;
    16.  
    17.    private string PlayerName;
    18.  
    19.    private string MatchName;
    20.    private string MatchPassword;
    21.  
    22.    public bool isLan = false;
    23.  
    24.    void Awake()
    25.    {
    26.      mgr.StartMatchMaker();
    27.    }
    28.  
    29.    /***
    30.     * Begin Button Network Functionality Code
    31.    ***/
    32.    public void OnHostLAN()
    33.    {
    34.      isLan = true;
    35.    }
    36.  
    37.    public void OnHostMatchMaker()
    38.    {
    39.      isLan = false;
    40.    }
    41.  
    42.    // Creates A Lobby
    43.    public void OnCreateLobby()
    44.    {
    45.      if (isLan)
    46.      {
    47.        mgr.matchMaker.CreateMatch("Test Game LAN", 8, true, "", "public address", "private address", 0, 0, mgr.OnMatchCreate);
    48.        // TODO: Setup Connection To LAN Lobby
    49.      }
    50.      else
    51.      {
    52.        mgr.matchMaker.CreateMatch("Test Game Matched", 8, true, "", "", "", 0, 0, mgr.OnMatchCreate);
    53.        // TODO: Setup Connection To Non-LAN Lobby
    54.      }
    55.    }
    56.  
    57.    // This Attempts to Connect To A Lobby
    58.    public void OnConnectToLobby()
    59.    {
    60.    }
    61.  
    62.    // This Refreshes The List Of Lobbies
    63.    public void OnRefreshGames()
    64.    {
    65.    }
    66.    /***
    67.     * End Button Network Functionality Code
    68.    ***/
    69.  
    70.    /***
    71.     * Begin GUI Controller Code
    72.    ***/
    73.    public void OnCreateMultiplayerMenu()
    74.    {
    75.      if (MainMenuPanel != null)
    76.        MainMenuPanel.SetActive(false);
    77.      if (CreateGamePanel != null)
    78.        CreateGamePanel.SetActive(true);
    79.      else
    80.        MainMenuPanel.SetActive(true);
    81.      if (JoinGamePanel != null)
    82.        JoinGamePanel.SetActive(false);
    83.      if (SettingsPanel != null)
    84.        SettingsPanel.SetActive(false);
    85.      if (CreditsPanel != null)
    86.        CreditsPanel.SetActive(false);
    87.    }
    88.  
    89.    public void OnJoinMultiplayerMenu()
    90.    {
    91.      if (MainMenuPanel != null)
    92.        MainMenuPanel.SetActive(false);
    93.      if (CreateGamePanel != null)
    94.        CreateGamePanel.SetActive(false);
    95.      if (JoinGamePanel != null)
    96.        JoinGamePanel.SetActive(true);
    97.      else
    98.        MainMenuPanel.SetActive(true);
    99.      if (SettingsPanel != null)
    100.        SettingsPanel.SetActive(false);
    101.      if (CreditsPanel != null)
    102.        CreditsPanel.SetActive(false);
    103.    }
    104.  
    105.    public void OnSettingsMenu()
    106.    {
    107.      if (MainMenuPanel != null)
    108.        MainMenuPanel.SetActive(false);
    109.      if (CreateGamePanel != null)
    110.        CreateGamePanel.SetActive(false);
    111.      if (JoinGamePanel != null)
    112.        JoinGamePanel.SetActive(false);
    113.      if (SettingsPanel != null)
    114.        SettingsPanel.SetActive(true);
    115.      else
    116.        MainMenuPanel.SetActive(true);
    117.      if (CreditsPanel != null)
    118.        CreditsPanel.SetActive(false);
    119.    }
    120.  
    121.    public void OnCreditsMenu()
    122.    {
    123.      if (MainMenuPanel != null)
    124.        MainMenuPanel.SetActive(false);
    125.      if (CreateGamePanel != null)
    126.        CreateGamePanel.SetActive(false);
    127.      if (JoinGamePanel != null)
    128.        JoinGamePanel.SetActive(false);
    129.      if (SettingsPanel != null)
    130.        SettingsPanel.SetActive(false);
    131.      if (CreditsPanel != null)
    132.        CreditsPanel.SetActive(true);
    133.      else
    134.        MainMenuPanel.SetActive(true);
    135.    }
    136.  
    137.    public void OnQuitGameMenu()
    138.    {
    139.    }
    140.  
    141.    public void OnReturnToMainMenu()
    142.    {
    143.      mgr.StopMatchMaker();
    144.  
    145.      if (CreateGamePanel != null)
    146.        CreateGamePanel.SetActive(false);
    147.      if (JoinGamePanel != null)
    148.        JoinGamePanel.SetActive(false);
    149.      if (SettingsPanel != null)
    150.        SettingsPanel.SetActive(false);
    151.      if (CreditsPanel != null)
    152.        CreditsPanel.SetActive(false);
    153.      if (MainMenuPanel != null)
    154.        MainMenuPanel.SetActive(true);
    155.    }
    156.    /***
    157.     * END GUI Controller Code
    158.    ***/
    159. }
    160.  

    EDIT: Updated the code.

    EDIT #2: Here's the error I've been getting when trying to create a lobby.
    NetworkLobbyManager can't accept new connection [hostId: -1 connectionId: 0 isReady: False channel count: 0], not in lobby and game already in progress.
     
    Last edited: Jun 3, 2016
  2. Tetra

    Tetra

    Joined:
    May 22, 2013
    Posts:
    29
    Anyone able to help me fix this error and/or tell me what I'm doing wrong? Searches for the error have yielded no results, thus far.
     
  3. Tetra

    Tetra

    Joined:
    May 22, 2013
    Posts:
    29
    Anybody?
     
  4. Tetra

    Tetra

    Joined:
    May 22, 2013
    Posts:
    29
    Bump...
     
  5. Tetra

    Tetra

    Joined:
    May 22, 2013
    Posts:
    29
    Anybody have an answer to this?
     
  6. rikey

    rikey

    Joined:
    Mar 3, 2015
    Posts:
    147
    Last edited: Jun 5, 2016
  7. Tetra

    Tetra

    Joined:
    May 22, 2013
    Posts:
    29
    Hrm, okay. I'll check this out and see if I can get things working.
     
  8. Tetra

    Tetra

    Joined:
    May 22, 2013
    Posts:
    29
    I have everything up and working and have successfully been able to modify the code to work within my GUI system. Thanks for the help!
     
    rikey likes this.
  9. bariscigal

    bariscigal

    Joined:
    Oct 26, 2009
    Posts:
    46
    EDIT : Ok my bad. I was using a pre-dated scene as the lobby scene. :/

    Hello,
    I have been using Unity 5.5.0p4 and right now i am changing the artwork for the lobby.
    And i am getting the same error:

    NetworkLobbyManager can't accept new connection

    NetworkManager:OnServerConnectInternal
    UnityEngine.Networking.NetworkManager:OnMatchCreate(Boolean, String, MatchInfo)
    Prototype.NetworkLobby.LobbyManager:OnMatchCreate(Boolean, String, MatchInfo) (at Assets/Lobby/Scripts/Lobby/LobbyManager.cs:246)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

    NetworkLobbyManager can't accept new connection [hostId: -1 connectionId: 0 isReady: False channel count: 0], not in lobby and game already in progress.
    UnityEngine.Networking.NetworkManager:OnMatchCreate(Boolean, String, MatchInfo)
    Prototype.NetworkLobby.LobbyManager:OnMatchCreate(Boolean, String, MatchInfo) (at Assets/Lobby/Scripts/Lobby/LobbyManager.cs:246)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

    RegisterHandlerSafe id:1 handler:OnLocalClientObjectDestroy
    UnityEngine.Networking.NetworkManager:OnMatchCreate(Boolean, String, MatchInfo)
    Prototype.NetworkLobby.LobbyManager:OnMatchCreate(Boolean, String, MatchInfo) (at Assets/Lobby/Scripts/Lobby/LobbyManager.cs:246)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

    I get this error as soon as i create the new match. if i close that panel and create a new match it works.
    Any chance you can share how you solved this error?
     
    Last edited: Feb 20, 2017
    snowbusiness likes this.
  10. kirov099

    kirov099

    Joined:
    Jun 28, 2017
    Posts:
    3
    I'm going to bump this in hopes that someone can provide a solution rather than a workaround. I'm familiar with the lobby example on the asset store, but the built in gui system for Unity doesn't play nice with VR. I've developed my own gui system instead, so I'd rather not go through the trouble of getting the example to work with my system. I've tried to keep things pretty simple, but I'm not sure what's going on here. Literally the only piece of networking code I've added so far is a call to StartHost(), which raises this error. It actually worked perfectly fine the very first time I ran it in the editor, but hasn't worked since. I thought this might be due to a socket not being closed properly or something, but restarting my computer, restarting my modem, and changing the port have had no effect on the problem. Any help would be appreciated.
     
    snowbusiness likes this.
  11. Russellinho

    Russellinho

    Joined:
    Jan 1, 2016
    Posts:
    8
    Anyone else having this problem may be because your lobby scene in your networkmanager component is not the correct scene. Changing it to the current lobby scene proactively fixed it for me.
     
unityunity