Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

After ending the game with StopHost(), previously connected clients can't join new games

Discussion in 'Multiplayer' started by mightybob, Jul 18, 2017.

  1. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    After calling StopHost() on the server and clients, the previously connected clients can no longer connect to any new games. (though new games can still be hosted)

    Should I be doing something else too?

    (note: not using Unity's matchmaker, I'm using NAT Punchthrough and my own server to set up initial connections)

    I'm using the latest version of Unity, 2017.1.0f3.
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    If you are using some custom Unity UI to interact with your "Custom Network Manager". Make sure you don't loose your script class refences when going back to the "Join Scene".

    Other than that. Instead of calling StopHost on clients. Use StopClient. And for Servers, use StopServer. Only use StopHost for the actual host. Might have something to do with it.
     
    mightybob and Deleted User like this.
  3. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    @mightybob Not sure, but I guess - StopHost will close socket, most probably you will need to punch Nat again?
     
    mightybob likes this.
  4. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Thanks, this was part of the problem. Been working on the problem ever since I posted here, just now got it fixed. Part of the issue was RakNet (what I'm using for punchthrough) needed to be shutdown and re-booted after leaving a match.

    Though I also had to Destroy() and re-Instantiate() the NetworkManager at the end of every match, too. I can't tell you why I had to do this, all I know is something was different (causing the player to be unable to join) after joining & disconnecting from a match, and due to lack of information online, resetting the NetworkManager to it's original state (via prefab) was kinda my only option. I know it sounds really hack-y, and it is, and although I'd rather know exactly what the hell was happening, it works perfectly fine and I don't see it causing any problems in the future.

    Thanks for the reply. Null references was my very first thought when this started happening a few weeks ago, triple checked everything and that was not the issue. Though the problem is fixed now as I mentioned above. I also tried StopHost/Client, in the end I ran StopHost on both host/client and it's all working as expected. (although it didn't when I used StopHost/Client)