I’m making an online multiplayer game with dedicated server and I find myself building the application very often as well as switching client and server build. To avoid having to check and uncheck scenes manually every time I’m trying to automate the process through an editor script.
public static void BuildServer()
{
//Scriptable object containing the scenes
AutoBuildSettings settings = AssetDatabase.LoadAssetAtPath<AutoBuildSettings>($@"{BUILD_SETTINGS_PATH}Server");
//Set "server build" to true
BuildPipeline.BuildPlayer(settings.scenes, @"ServerBuild", BuildTarget.StandaloneWindows, BuildOptions.None);
}
I cannot find a way to set or even access the “server build” variable, does anyone know where it is if it is somewhere?
If i am not mistaken unity still has not really adressed this issue as the “server-build” is not really what most people expect it to be.
as can be read here in the build settings docu server build does the following:
Enable this checkbox to build the Player for server use and with no visual elements (headless) without the need for any command line options.
When you enable this option, Unity builds managed scripts with the UNITY_SERVER define, which means you can write server-specific code for your applications. […]
As you can see this checkbox does not really do anything except for 2 things:
- add the precompiler definition
UNITY_SERVER
- add the build option
EnableHeadlessMode
so the latter can be set as value of the buildoption enum as argument for your build pipeline.
Let me know if that helped.
Debug.Log(EditorUserBuildSettings.enableHeadlessMode);
Is what I found, but I am not sure if you can rewrite it though.
It’s really useful especially if you need to know if it is a server build or not DURING/BEFORE the build process
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
class PreBuild : IPreprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
public void OnPreprocessBuild(BuildReport report)
{
Debug.Log(EditorUserBuildSettings.enableHeadlessMode);
}
}