Unity
Unity supports dedicated server builds through its Dedicated Server platform target, available since Unity 2021.3 LTS. Prior versions require manual configuration to strip client systems.
Dedicated Server Platform Target
Section titled “Dedicated Server Platform Target”Starting with Unity 2021.3, you can select Dedicated Server as a build target in Build Settings. This platform target:
- Strips the rendering pipeline
- Removes audio systems
- Excludes textures, shaders, and other visual assets from the build
- Produces a significantly smaller binary
In Build Settings: File > Build Settings > Platform > Dedicated Server, then select your target OS (Linux or Windows).
If you’re on an older Unity version, use -batchmode -nographics flags at launch and manually manage which assets are included.
Headless Launch Flags
Section titled “Headless Launch Flags”| Flag | Purpose |
|---|---|
-batchmode | Run without creating a window or requiring user interaction |
-nographics | Skip GPU initialization entirely |
-logFile <path> | Write logs to a specific file (use - for stdout) |
-port <N> | Set listening port (if your netcode reads this) |
A typical launch command:
./YourServer -batchmode -nographics -logFile -port 7777Note: With the Dedicated Server platform target, -batchmode and -nographics are already implied. You only need these flags if you’re running a standalone (non-server-target) build as a server.
IL2CPP vs. Mono
Section titled “IL2CPP vs. Mono”For production server builds, you have two scripting backend options:
IL2CPP (recommended for production)
- Compiles C# to native C++ code
- Better runtime performance
- Larger build size and longer build times
- Required for some platforms
Mono
- Faster build iteration during development
- Slightly larger runtime memory overhead
- Fine for development and testing
For production Linux servers, IL2CPP is the standard choice. Mono works but has slightly higher overhead per instance, which adds up when a Hosting Providers is running dozens of servers per machine.
Stripping Managed Code
Section titled “Stripping Managed Code”Unity can strip unused managed code to reduce build size. In Player Settings:
- Managed Stripping Level: Set to Medium or High for server builds
- Test thoroughly after enabling stripping, as aggressive stripping can remove code accessed only through reflection
If you use reflection or dynamic type loading, add a link.xml file to preserve those types.
Asset Management
Section titled “Asset Management”Even with the Dedicated Server target, Unity includes assets referenced by scenes and prefabs. To minimize server build size:
- Keep server-only scenes separate from client scenes
- Use Addressables or Asset Bundles to load client visuals separately
- Avoid referencing materials, textures, or audio clips from server-side scripts
- Use
#if UNITY_SERVERpreprocessor defines to exclude client-only code paths
Netcode Considerations
Section titled “Netcode Considerations”Unity offers multiple networking solutions. Regardless of which you use (Netcode for GameObjects, Mirror, FishNet, custom), ensure:
- Your transport layer works without a graphics context
- Server-side logic does not reference any UnityEngine.UI or rendering components
- Network tick rate is configurable via startup arguments or config files
Common Pitfalls
Section titled “Common Pitfalls”Missing Linux dependencies: Unity’s Linux server builds depend on specific system libraries. Common missing dependencies include libstdc++, libgcc, and libc6. Test on a clean Linux environment, not just your development machine.
Coroutines and WaitForEndOfFrame: WaitForEndOfFrame does not work in -batchmode because there is no frame to render. Use WaitForFixedUpdate or time-based waits on the server.
PlayerPrefs on servers: PlayerPrefs may not work as expected on headless Linux. Use file-based configuration instead.