diff --git a/Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs b/Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs index daf4137c1..c55c1ebb4 100644 --- a/Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs +++ b/Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs @@ -62,11 +62,10 @@ public static long RandomLong() /// public virtual void Start() { - // headless mode? then start advertising - if (NetworkManager.isHeadless) - { - AdvertiseServer(); - } + // Server mode? then start advertising +#if UNITY_SERVER + AdvertiseServer(); +#endif } // Ensure the ports are cleared no matter when Game/Unity UI exits diff --git a/Assets/Mirror/Examples/Room/Scripts/NetworkRoomManagerExt.cs b/Assets/Mirror/Examples/Room/Scripts/NetworkRoomManagerExt.cs index bce48460f..6313609ed 100644 --- a/Assets/Mirror/Examples/Room/Scripts/NetworkRoomManagerExt.cs +++ b/Assets/Mirror/Examples/Room/Scripts/NetworkRoomManagerExt.cs @@ -55,10 +55,11 @@ Setting showStartButton false when the button is pressed hides it in the game sc public override void OnRoomServerPlayersReady() { // calling the base method calls ServerChangeScene as soon as all players are in Ready state. - if (isHeadless) - base.OnRoomServerPlayersReady(); - else - showStartButton = true; +#if UNITY_SERVER + base.OnRoomServerPlayersReady(); +#else + showStartButton = true; +#endif } public override void OnGUI() diff --git a/Assets/Mirror/Runtime/Logging/NetworkHeadlessLogger.cs b/Assets/Mirror/Runtime/Logging/NetworkHeadlessLogger.cs index d41bc2e06..a6e85b68d 100644 --- a/Assets/Mirror/Runtime/Logging/NetworkHeadlessLogger.cs +++ b/Assets/Mirror/Runtime/Logging/NetworkHeadlessLogger.cs @@ -14,10 +14,9 @@ public class NetworkHeadlessLogger : MonoBehaviour void Awake() { - if (NetworkManager.isHeadless) - { - LogFactory.ReplaceLogHandler(new ConsoleColorLogHandler(showExceptionStackTrace)); - } +#if UNITY_SERVER + LogFactory.ReplaceLogHandler(new ConsoleColorLogHandler(showExceptionStackTrace)); +#endif } } } diff --git a/Assets/Mirror/Runtime/NetworkManager.cs b/Assets/Mirror/Runtime/NetworkManager.cs index 36d147914..99cb95ae7 100644 --- a/Assets/Mirror/Runtime/NetworkManager.cs +++ b/Assets/Mirror/Runtime/NetworkManager.cs @@ -45,10 +45,15 @@ public class NetworkManager : MonoBehaviour /// /// Automatically invoke StartServer() - /// If the application is a Server Build or run with the -batchMode command line arguement, StartServer is automatically invoked. + /// If the application is a Server Build, StartServer is automatically invoked. + /// Server build is true when "Server build" is checked in build menu, or BuildOptions.EnableHeadlessMode flag is in BuildOptions /// - [Tooltip("Should the server auto-start when the game is started in a headless build?")] - public bool startOnHeadless = true; + [Tooltip("Should the server auto-start when 'Server Build' is checked in build settings")] + [FormerlySerializedAs("startOnHeadless")] + public bool autoStartServerBuild = true; + + [Obsolete("Use autoStartServerBuild instead.")] + public bool startOnHeadless { get => autoStartServerBuild; set => autoStartServerBuild = value; } /// /// Enables verbose debug messages in the console @@ -185,6 +190,7 @@ public class NetworkManager : MonoBehaviour /// /// headless mode detection /// + [Obsolete("Use #if UNITY_SERVER instead.")] public static bool isHeadless => SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null; // helper enum to know if we started the networkmanager as server/client/host. @@ -255,10 +261,12 @@ public virtual void Start() // some transports might not be ready until Start. // // (tick rate is applied in StartServer!) - if (isHeadless && startOnHeadless) +#if UNITY_SERVER + if (autoStartServerBuild) { StartServer(); } +#endif } // NetworkIdentity.UNetStaticUpdate is called from UnityEngine while LLAPI network is active. @@ -675,15 +683,10 @@ public virtual void OnApplicationQuit() /// public virtual void ConfigureServerFrameRate() { - // set a fixed tick rate instead of updating as often as possible - // * if not in Editor (it doesn't work in the Editor) - // * if not in Host mode -#if !UNITY_EDITOR - if (!NetworkClient.active && isHeadless) - { - Application.targetFrameRate = serverTickRate; - if (logger.logEnabled) logger.Log("Server Tick Rate set to: " + Application.targetFrameRate + " Hz."); - } + // only set framerate for server build +#if UNITY_SERVER + Application.targetFrameRate = serverTickRate; + if (logger.logEnabled) logger.Log("Server Tick Rate set to: " + Application.targetFrameRate + " Hz."); #endif } diff --git a/Assets/Mirror/Tests/Editor/NetworkManagerTest.cs b/Assets/Mirror/Tests/Editor/NetworkManagerTest.cs index d88705ec4..11f73a852 100644 --- a/Assets/Mirror/Tests/Editor/NetworkManagerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkManagerTest.cs @@ -29,7 +29,7 @@ public void VariableTest() { Assert.That(manager.dontDestroyOnLoad, Is.True); Assert.That(manager.runInBackground, Is.True); - Assert.That(manager.startOnHeadless, Is.True); + Assert.That(manager.autoStartServerBuild, Is.True); Assert.That(manager.showDebugMessages, Is.False); Assert.That(manager.serverTickRate, Is.EqualTo(30)); Assert.That(manager.offlineScene, Is.Empty); diff --git a/Assets/Mirror/Tests/Runtime/HostSetup.cs b/Assets/Mirror/Tests/Runtime/HostSetup.cs index a72cb660b..2871f703d 100644 --- a/Assets/Mirror/Tests/Runtime/HostSetup.cs +++ b/Assets/Mirror/Tests/Runtime/HostSetup.cs @@ -27,7 +27,7 @@ public IEnumerator SetupHost() identity.assetId = System.Guid.NewGuid(); manager.playerPrefab = playerGO; - manager.startOnHeadless = false; + manager.autoStartServerBuild = false; yield return null;