Unity headless mode as a game server?

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?

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.

1 Like

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.

2 Likes

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?

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.

Depends on the game, small fps games? Sure it will work. large scale open world games will not.

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 :slight_smile:

Imho use Unity, but with as many open source components as possible to minimize risk.

1 Like

What makes you think a large scale open world game can’t work using a Unity headless server? I’ve been having good results.

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.

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.

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.

3 Likes

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.

14 Likes