Search Unity

Question Different scene instanses

Discussion in 'Multiplayer' started by Jicefrost, Aug 20, 2022.

  1. Jicefrost

    Jicefrost

    Joined:
    May 13, 2019
    Posts:
    40
    Game for example - chess. 2 player using ip/relay/lobby(no matter what) -> connecting to dedicated server. Press "play" button and starts the game. Another 3rd player try to connect and receive error that the game already started or port is busy. So I decided to make sort of adminpanel on server:

    Player 1 and 2 connect to server to ip n.n.n.n:7733 received port 7745 and on serve side launched another .exe application with port 7745 (server mode), players disconnecting from 7733 and connecting to 7745. Player 3 connect to ip n.n.n.n:7733 received port 7746 and on serve side launched another .exe application with port 7746 (server mode) and so on.
    adminpanel controls all launched games, close them if they "stuck" and etc..

    Everything working well but to many launches .exe going. if 10 players will play chess this will mean that 5 .exe will run on server.

    What is the right way to play multiple game sessions on dedicated server for example 100 players 1 vs 1 ? Load multiple scenes at one time on single "server_application".exe ? tell me please where to go
     
  2. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    You did not say which networking solution you were using.

    You could load a new executable per match but that would use a lot more resources than running many matches in a single server. Scene stacking, as I call it, is a great solution for this.

    If you're still in the planning stage it could be worth your time to check out Lobby and Worlds. It's literally made for this exact thing.
    https://fish-networking.gitbook.io/docs/master/pro

    If you're on a different networking solution let me know.
     
  3. Jicefrost

    Jicefrost

    Joined:
    May 13, 2019
    Posts:
    40
    sorry did not say yes - my network solution Netcode for Gameobj. for lobby/relay using unity multiplayer services. My Question more theoretically - how is the "right" thing to do this?

    bacause my 2nd prototype game and same question always came - 1, 2, 3 players yes ok. -> 100 players came troubles :)
     
  4. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    I wouldn't say there is a right or wrong way, but loading multiple matches on a single executable will definitely save you cost. For something as simple as a chess game as well, you could most definitely have hundreds of games on one executable.
     
    Jicefrost likes this.
  5. Jicefrost

    Jicefrost

    Joined:
    May 13, 2019
    Posts:
    40
    Is unity may "run multiple scenes per time" in one executable ? I need to procedure generate "scene file" and delete it after players left?
     
  6. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    660
    Netcode's SceneManager by default will make sure all clients are running in the same scene with all spawned network objects. To achieve what you want you'll need to disable scene management and take responsibility of what clients should be in which scene and what objects should be spawned. It's currently what I'm doing in case you need any guidance.
     
  7. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    Just keep in mind when you do scene stack(different instances) that you set the physics scene type when loading the new scene; that is, only if you need physics in your scenes.

    Otherwise the physics over scenes will interact with each other.
     
    Jicefrost likes this.
  8. Jicefrost

    Jicefrost

    Joined:
    May 13, 2019
    Posts:
    40
    yes I need physics :(

    same thing Im doing. you using Netcode?
     
  9. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    660
    Yes this is using Netcode but the game is relatively simple, no physics to worry about. It will support running multiple instances of the game within one server executable.
     
  10. Jicefrost

    Jicefrost

    Joined:
    May 13, 2019
    Posts:
    40
    "within one server executable." you using one networkmanager for each scene?
    My game - player side - player connect to server, server tolds player - go to this port -> player disconnecting - connect to new port
    server side - server see request from player , give him new port, loading new scene, on this new scene there is ANOTHER network manager with new port -> networkmanager.startServer() and players connect to this new scene with new networkmanager/port. (here im stuck, because network manager is singelton and it works on whole project)
     
  11. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    660
    Ah, no nothing that complicated. There is only one network manager, when the server starts it moves to a new 'server scene' and never leaves there. It just handles client requests are they come in. I can go into more detail on the workflow, I need to reacquaint myself with it anyway as I've not looked at in months and it needs a lot of improvement.

    To be honest if you have a set up already of running a new server exe for each game I would stick with that, it provides better separation and is far more scalable should you move on to more complex games.
     
    Last edited: Aug 26, 2022
    Jicefrost likes this.
  12. Jicefrost

    Jicefrost

    Joined:
    May 13, 2019
    Posts:
    40
    This I already have and it works well thank you :) . its just ceepeng about 100 . exe files for 200 players is same time with physics... my server told me that Im going crazy :( I was hoping that this can be done in a single .exe.

    well anyway thanks you all