Search Unity

Having multiple network managers in the same scene

Discussion in 'Netcode for GameObjects' started by cerestorm, Jan 7, 2023.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    I've created my multiplayer application to be a self-contained package of a lobby (as in a lobby containing multiple rooms), rooms and multiple game instances. This runs well enough although roughly, but the game is getting too complicated to be run this way and won't support many instances without a lot of server optimisations which is going to get really tedious going forward.

    To that end I'm switching over to having a portal server for the lobby and rooms and launch separate game instances. What would be ideal is have two network managers, one for portal <-> instance communication and one for portal <-> clients. Would it be possible to have two NetworkManagers in the same scene? I know that would mean NetworkManager.Singleton goes out the window but are there any technical reasons preventing this?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,956
    You can only have one NetworkManager. I wonder, why aren't you relying on Unity's Lobby service?

    In any case, you don't need NGO to communicate between Lobby and server instance. The practical implementation would have you store game session info in a (online) database so the server instance can get the Lobby settings from that, and when the game ends it writes back to that database where the Lobby can get the session data (eg number of kills for each player). There shouldn't be any need for realtime communication between Lobby and server instance.
     
    RikuTheFuffs-U likes this.
  3. Evil-Otaku

    Evil-Otaku

    Joined:
    Oct 17, 2012
    Posts:
    72
    Technically, you can have more than one network manager. But it's meant more for unit testing. Trying to make your own Lobby service doesn't seem like a good use of time and effort
     
  4. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    That's an interesting idea but isn't quite what I had in mind. I want to have it setup so the portal hosts the lobby for clients to initially join and they can create and join rooms from there. The idea is to allow multiple games to be supported with clients directed to the right lobby on connection. The only thing I can think of that did something broadly similar is MPlayer if you remember it. I don't think Lobby is a good fit for this but I could be wrong.

    You're right there isn't a need for realtime communication but I'd like it in some form so the portal can keep track of the state of its instances. I did a very superficial test which showed that two network managers may be possible but I'm not overly keen on the idea in case it works for now but breaks on a later NGO update. I can just share a single network manager but giving it dual responsibility is going to mean the code isn't as clean as I want it to be.

    There are other options, I just need to work out the best way forward.
     
  5. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    Agreed, I don't want to re-invent the wheel but want to create something broader than just Lobby itself.