Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Unity headless mode as a game server?

Discussion in 'Multiplayer' started by sinaari, Aug 18, 2020.

  1. sinaari

    sinaari

    Joined:
    Jan 28, 2019
    Posts:
    47
    Hi! Is Unity running in headless mode a viable solution for a game server? It would allow to use all the convenient assets, for example significantly easing impementation of pathfinding and other game logic. But something tells me that this is not the most popular option?

    What are the drawbacks of using Unity headless mode for a game server?
     
    Last edited: Aug 18, 2020
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I certainly hope so, because that's what I've been doing. Many network libraries for Unity use this approach when using a dedicated server. Mirror is a popular one for example.

    While you get all the benefits and features of Unity, you also get all the overhead and limitations of Unity. For example, Unity doesn't support multiple independent worldspaces, so if you want to run multiple independent matches on the same server the most direct solution is to run multiple instances of your server build. That approach works, but is not particularly memory efficient loading a lot of the same stuff for each instance.
     
    sinaari likes this.
  3. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    I believe headless, for Linux anyways, has been renamed to "Server Build". At least it is for me in Unity 2019.3. So I'm assuming that is their main intent behind it.

    I currently use a linux headless / server build for my game servers. I'm also using nav mesh and nav mesh agents on the server for AI characters (The resulting positions get synced to clients). I would say the main benefits are simplifying the dev process and having access to all the scene data on the server. Game objects, geometry, collision volumes etc. There are probably lighter ways of handling server logic but it's pretty straight forward when you have access to everythingyou need. If you use Unet and I'm assuming Mirror, building a server and client version is just a couple different build settings.
     
    Joe-Censored and sinaari like this.
  4. sinaari

    sinaari

    Joined:
    Jan 28, 2019
    Posts:
    47
    Thanks for the answers! I have another question then:

    Do you use the batchmode or do you make server builds? And if you use the batchmode, then it only allows specifying the entrypoint but does not naturally engage with the standard Unity routines, so how do you load the scene and manage its lifecycle and GameObjects within it?
     
  5. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    I would only use batchmode if you want to run the server in the background without any window, if you want a console window then make a server build.
     
  6. beheadedwarrior

    beheadedwarrior

    Joined:
    Jul 24, 2020
    Posts:
    8
    Depends on the game, small fps games? Sure it will work. large scale open world games will not.
     
  7. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    The biggest drawback is launching your server into a black box and hoping to not encounter critical bugs.
    Unity's move to packages is a big step forward, since they all ship with C# source so you could fix bugs yourself.
    Most of the MonoBehaviour tools like Navigation still run in the C++ black box, so there is definitely risk.

    Using an external game server is less risky, but also a lot more work which is why we try doing that in Unity :)

    Imho use Unity, but with as many open source components as possible to minimize risk.
     
    JesOb likes this.
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    What makes you think a large scale open world game can't work using a Unity headless server? I've been having good results.
     
  9. beheadedwarrior

    beheadedwarrior

    Joined:
    Jul 24, 2020
    Posts:
    8
    Common sense tells you that wont scale well. Maybe once ecs is stable yes but other than that you're better off writing your own server with a thin physics layer on top of it.
     
  10. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    I am not really sure what your are refering to, you wrote "large scale open worlds", I don't see why this wouldn't work with unity, I think you might be talking about MMO's which is a totally different topic.
     
  11. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You just implement multiple server instances to cover different areas of the map. Seems to work fine for me, contrary to "common sense" I guess.
     
  12. Christian-Tucker

    Christian-Tucker

    Joined:
    Aug 18, 2013
    Posts:
    376
    Gravedigger alert.

    I know I'm late, but people will likely find this topic through google (as I did while looking for something completely unrelated). This method is quite alright and ideal. You can use unity's headless mode for very large worlds containing thousands of entities, I know because I've done it myself in production. Keep in mind that headless mode just detaches the renderer, but doesn't actually handle the removal of rendering components. To get better performance make sure to manually remove cameras, lighting, renderers, static meshes, etc. from your scenes.