Search Unity

Question Unity Netcode performance Server with much GameObjects

Discussion in 'Netcode for GameObjects' started by Andreas12345, Oct 30, 2022.

  1. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    When i start as:
    Code (CSharp):
    1. NetworkManager.Singleton.StartServer();
    I have scenes with much GameObjects, but as a server they are not needed (*i think.)

    But the objects are loaded, and disable or destroy after load sounds wrong to me, because it makes sense to not load the Objects when not needed as a server.
    Is there a "Gold" click to avoid the complete loading of the scene when start as ded. Server?
     
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    On the NetworkManager in the Unity inspector you can untick 'Enable Scene Management'. The upside of this is that the server and clients can be scenes independent of each other. The downside is you'll have to take responsibility of what client should be in which scene and what network objects to show to them.
     
    Andreas12345 likes this.
  3. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    Ah cool, ill check this out :)
     
  4. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    When i untick 'Enable Scene Management' , its make no difference, scene is complete loaded
     
  5. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    You'll probably want to put the server into a scene of its own. The way I have it is for the server to subscribe to NetworkManager.Singleton.OnServerStarted and in that callback call SceneManager.LoadScene("Server").
     
    Andreas12345 likes this.
  6. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    Ah ok, i never did this before that way. i give this a try, thx for pointing me on that.
     
  7. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    I like to ask again, because i am not that good in it.

    I have my LobbyManager:
    https://github.com/Landixus/ToolsForUnity/blob/master/LobbyManager.cs
    Thats probably the wrong place to do this!?
    In my RelayManager i Create Dedicated server, Host and Join a Game:
    https://github.com/Landixus/ToolsForUnity/blob/master/RelayManager.cs
    And in my LevelManager i load the selected scene.

    in My First Scene "UserMenu" i have always this:
    upload_2022-11-4_13-30-19.png

    RedHost should start the Server, HOST starts nonDedicatedHost.
    If Player pressed the Join:
    pops a Panel to front with current joinable games:
    upload_2022-11-4_13-32-16.png


    I am a bit Lost here :(
     
  8. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    So am I :D Just to clarify, if you're running a dedicated server you won't also have a host playing on that server, only clients that can join it.

    What setup are you trying to run, dedicated server or one player as server/host?
     
  9. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    I like to give the possibility to:
    0 Start a Server, for example on a separate PC.
    1 Start a Host where the Host can Host and play :) *Its working
    2 Join a Host as a client. * Its working

    3 SinglePlayer (Ok thats working good) :)

    In the old Quake III time i just start Quake3.exe +set dedicated2 +map pro-q3dm6 :) just form the console.
     
  10. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    I don't think I played that map :) not the pro version anyway.

    It sounds like you've done pretty good so far. I've not thought about being able to host and be a dedicated server in one exe, I'm not sure how feasible that is. Unity would probably recommend having a separate server exe and using Multiplay. I wonder how it worked in Quake 3, either by launching a separate server exe or by running an entirely different code set I would imagine.

    You'd have to work out could you just have a lot of conditional checks for being a dedicated server in the current game, or run a separate set of code entirely, I would lean towards the latter. If you want to keep things substantially the same, how would you handle the lobby. For the server you'd have to disable all drawing and input, anything related to a host client being in the lobby itself, and presumably allow for the first client joining to host. There's also the question of where the server is hosted and how to connect to it.

    I would say having a dedicated server build is the way to go. If you want to keep Netcode's scene management you'll still have to deal with the above issues, if you want to handle the scene management yourself that means writing more code for the handling of that.

    I'd have to give it more thought but on the face of it I'd say catering for both server/host and dedicated server sounds a bit too complicated for my liking. :)
     
    Andreas12345 likes this.
  11. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    Ok so we do a dedServer or we do not.
    Player can start another instance if server is started.

    I also never did that before. :)