Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Assets/Mirror/Components/Discovery/NetworkDiscoveryHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Reset()
#if !UNITY_SERVER
void OnGUI()
{
if (NetworkManager.singleton == null)
if (NetworkManager.Instance == null)
return;

if (!NetworkClient.isConnected && !NetworkServer.active && !NetworkClient.active)
Expand All @@ -64,15 +64,15 @@ void DrawGUI()
if (GUILayout.Button("Start Host"))
{
discoveredServers.Clear();
NetworkManager.singleton.StartHost();
NetworkManager.Instance.StartHost();
networkDiscovery.AdvertiseServer();
}

// Dedicated server
if (GUILayout.Button("Start Server"))
{
discoveredServers.Clear();
NetworkManager.singleton.StartServer();
NetworkManager.Instance.StartServer();
networkDiscovery.AdvertiseServer();
}

Expand Down Expand Up @@ -102,7 +102,7 @@ void StopButtons()
{
if (GUILayout.Button("Stop Host"))
{
NetworkManager.singleton.StopHost();
NetworkManager.Instance.StopHost();
networkDiscovery.StopDiscovery();
}
}
Expand All @@ -111,7 +111,7 @@ void StopButtons()
{
if (GUILayout.Button("Stop Client"))
{
NetworkManager.singleton.StopClient();
NetworkManager.Instance.StopClient();
networkDiscovery.StopDiscovery();
}
}
Expand All @@ -120,7 +120,7 @@ void StopButtons()
{
if (GUILayout.Button("Stop Server"))
{
NetworkManager.singleton.StopServer();
NetworkManager.Instance.StopServer();
networkDiscovery.StopDiscovery();
}
}
Expand All @@ -132,7 +132,7 @@ void StopButtons()
void Connect(ServerResponse info)
{
networkDiscovery.StopDiscovery();
NetworkManager.singleton.StartClient(info.uri);
NetworkManager.Instance.StartClient(info.uri);
}

public void OnDiscoveredServer(ServerResponse info)
Expand Down
8 changes: 4 additions & 4 deletions Assets/Mirror/Components/NetworkRoomPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class NetworkRoomPlayer : NetworkBehaviour
/// </summary>
public virtual void Start()
{
if (NetworkManager.singleton is NetworkRoomManager room)
if (NetworkManager.Instance is NetworkRoomManager room)
{
// NetworkRoomPlayer object must be set to DontDestroyOnLoad along with NetworkRoomManager
// in server and all clients, otherwise it will be respawned in the game scene which would
Expand All @@ -64,7 +64,7 @@ public virtual void Start()

public virtual void OnDisable()
{
if (NetworkClient.active && NetworkManager.singleton is NetworkRoomManager room)
if (NetworkClient.active && NetworkManager.Instance is NetworkRoomManager room)
{
// only need to call this on client as server removes it before object is destroyed
room.roomSlots.Remove(this);
Expand All @@ -81,7 +81,7 @@ public virtual void OnDisable()
public void CmdChangeReadyState(bool readyState)
{
readyToBegin = readyState;
NetworkRoomManager room = NetworkManager.singleton as NetworkRoomManager;
NetworkRoomManager room = NetworkManager.Instance as NetworkRoomManager;
if (room != null)
{
room.ReadyStatusChanged();
Expand Down Expand Up @@ -134,7 +134,7 @@ public virtual void OnGUI()
if (!showRoomGUI)
return;

NetworkRoomManager room = NetworkManager.singleton as NetworkRoomManager;
NetworkRoomManager room = NetworkManager.Instance as NetworkRoomManager;
if (room)
{
if (!room.showRoomGUI)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Components/RemoteStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ protected override void OnValidate()
// public so it can also be called from tests (and be overwritten by users)
public override void OnStartServer()
{
NetworkStatistics = NetworkManager.singleton.GetComponent<NetworkStatistics>();
if (NetworkStatistics == null) throw new Exception($"RemoteStatistics requires a NetworkStatistics component on {NetworkManager.singleton.name}!");
NetworkStatistics = NetworkManager.Instance.GetComponent<NetworkStatistics>();
if (NetworkStatistics == null) throw new Exception($"RemoteStatistics requires a NetworkStatistics component on {NetworkManager.Instance.name}!");

if (!requiresPasswordAuth)
{
Expand Down
23 changes: 13 additions & 10 deletions Assets/Mirror/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ public class NetworkManager : MonoBehaviour
[Header("Interpolation UI - Requires Editor / Dev Build")]
public bool timeInterpolationGui = false;

// DEPRECATED 2025-07-29
[Obsolete("Use .instance instead of .singleton")]
public static NetworkManager singleton => Instance;
/// <summary>The one and only NetworkManager</summary>
public static NetworkManager singleton { get; internal set; }
public static NetworkManager Instance { get; internal set; }

/// <summary>Number of active player objects across all connections on the server.</summary>
public int numPlayers => NetworkServer.connections.Count(kv => kv.Value.identity != null);
Expand Down Expand Up @@ -692,21 +695,21 @@ public virtual void ConfigureHeadlessFrameRate()

bool InitializeSingleton()
{
if (singleton != null && singleton == this)
if (Instance != null && Instance == this)
return true;

if (dontDestroyOnLoad)
{
if (singleton != null)
if (Instance != null)
{
Debug.LogWarning("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will be destroyed.");
Destroy(gameObject);

// Return false to not allow collision-destroyed second instance to continue.
return false;
}
//Debug.Log("NetworkManager created singleton (DontDestroyOnLoad)");
singleton = this;
//Debug.Log("NetworkManager created instance (DontDestroyOnLoad)");
Instance = this;
if (Application.isPlaying)
{
// Force the object to scene root, in case user made it a child of something
Expand All @@ -717,8 +720,8 @@ bool InitializeSingleton()
}
else
{
//Debug.Log("NetworkManager created singleton (ForScene)");
singleton = this;
//Debug.Log("NetworkManager created instance (ForScene)");
Instance = this;
}

// set active transport AFTER setting singleton.
Expand Down Expand Up @@ -777,8 +780,8 @@ void RegisterClientMessages()
public static void ResetStatics()
{
// call StopHost if we have a singleton
if (singleton)
singleton.StopHost();
if (Instance)
Instance.StopHost();

// reset all statics
startPositions.Clear();
Expand All @@ -788,7 +791,7 @@ public static void ResetStatics()
networkSceneName = string.Empty;

// and finally (in case it isn't null already)...
singleton = null;
Instance = null;
}

// virtual so that inheriting classes' OnDestroy() can call base.OnDestroy() too
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using Mirror.Examples.AssignAuthority;
using UnityEngine;
using UnityEngine.SceneManagement;

Expand All @@ -7,7 +9,10 @@ namespace Mirror.Examples.AdditiveLevels
[AddComponentMenu("")]
public class AdditiveLevelsNetworkManager : NetworkManager
{
public static new AdditiveLevelsNetworkManager singleton => (AdditiveLevelsNetworkManager)NetworkManager.singleton;
// DEPRECATED 2025-07-29
[Obsolete("Use .instance instead of .singleton")]
public static new AdditiveLevelsNetworkManager singleton => Instance;
public static new AdditiveLevelsNetworkManager Instance => (AdditiveLevelsNetworkManager)NetworkManager.Instance;

[Header("Additive Scenes - First is start scene")]

Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Examples/AdditiveLevels/Scripts/Portal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ IEnumerator SendPlayerToNewScene(GameObject player)
conn.Send(new SceneMessage { sceneName = gameObject.scene.path, sceneOperation = SceneOperation.UnloadAdditive, customHandling = true });

// wait for fader to complete.
yield return new WaitForSeconds(AdditiveLevelsNetworkManager.singleton.fadeInOut.GetFadeInTime());
yield return new WaitForSeconds(AdditiveLevelsNetworkManager.Instance.fadeInOut.GetFadeInTime());

// Remove player after fader has completed
NetworkServer.RemovePlayerForConnection(conn, RemovePlayerOptions.Unspawn);
Expand Down
30 changes: 15 additions & 15 deletions Assets/Mirror/Examples/AutoLANClientController/Scripts/CanvasHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void Start()
buttonAuto.onClick.AddListener(ButtonAuto);

//Update the canvas text if you have manually changed network managers address from the game object before starting the game scene
inputFieldAddress.text = NetworkManager.singleton.networkAddress;
inputFieldAddress.text = NetworkManager.Instance.networkAddress;

//Adds a listener to the input field and invokes a method when the value changes.
inputFieldAddress.onValueChanged.AddListener(delegate { OnValueChangedAddress(); });
Expand All @@ -45,7 +45,7 @@ private void Start()
networkDiscovery = GameObject.FindAnyObjectByType<AutoLANNetworkDiscovery>();
#else
// Deprecated in Unity 2023.1
networkDiscovery = GameObject.FindObjectOfType<AutoLANNetworkDiscovery>();
networkDiscovery = GameObject.FindObjectOfType<AutoLANNetworkDiscovery>();
#endif
}

Expand Down Expand Up @@ -75,14 +75,14 @@ public IEnumerator Waiter()
}
yield return new WaitForSeconds(1.0f);
discoveredServers.Clear();
// NetworkManager.singleton.onlineScene = SceneManager.GetActiveScene().name;
// NetworkManager.instance.onlineScene = SceneManager.GetActiveScene().name;
if (runAsPlayerHost == true)
{
NetworkManager.singleton.StartHost();
NetworkManager.Instance.StartHost();
}
else
{
NetworkManager.singleton.StartServer();
NetworkManager.Instance.StartServer();
}
networkDiscovery.AdvertiseServer();
}
Expand All @@ -92,7 +92,7 @@ void Connect(ServerResponse info)
{
infoText.text = "Connecting to: " + info.serverId;
networkDiscovery.StopDiscovery();
NetworkManager.singleton.StartClient(info.uri);
NetworkManager.Instance.StartClient(info.uri);
}

public void OnDiscoveredServer(ServerResponse info)
Expand All @@ -105,8 +105,8 @@ public void ButtonHost()
{
SetupInfoText("Starting as host");
discoveredServers.Clear();
//NetworkManager.singleton.onlineScene = SceneManager.GetActiveScene().name;
NetworkManager.singleton.StartHost();
//NetworkManager.instance.onlineScene = SceneManager.GetActiveScene().name;
NetworkManager.Instance.StartHost();
networkDiscovery.AdvertiseServer();

}
Expand All @@ -115,8 +115,8 @@ public void ButtonServer()
{
SetupInfoText("Starting as server.");
discoveredServers.Clear();
// NetworkManager.singleton.onlineScene = SceneManager.GetActiveScene().name;
NetworkManager.singleton.StartServer();
// NetworkManager.instance.onlineScene = SceneManager.GetActiveScene().name;
NetworkManager.Instance.StartServer();
networkDiscovery.AdvertiseServer();

}
Expand All @@ -134,17 +134,17 @@ public void ButtonStop()
// stop host if host mode
if (NetworkServer.active && NetworkClient.isConnected)
{
NetworkManager.singleton.StopHost();
NetworkManager.Instance.StopHost();
}
// stop client if client-only
else if (NetworkClient.isConnected)
{
NetworkManager.singleton.StopClient();
NetworkManager.Instance.StopClient();
}
// stop server if server-only
else if (NetworkServer.active)
{
NetworkManager.singleton.StopServer();
NetworkManager.Instance.StopServer();
}
networkDiscovery.StopDiscovery();
// we need to call setup canvas a second time in this function for it to update the abovee changes
Expand All @@ -162,7 +162,7 @@ public void SetupCanvas()
{
// Here we will dump majority of the canvas UI

if (NetworkManager.singleton == null)
if (NetworkManager.Instance == null)
{
SetupInfoText("NetworkManager null");
return;
Expand Down Expand Up @@ -199,7 +199,7 @@ public void SetupInfoText(string _info)
// Invoked when the value of the text field changes.
public void OnValueChangedAddress()
{
NetworkManager.singleton.networkAddress = inputFieldAddress.text;
NetworkManager.Instance.networkAddress = inputFieldAddress.text;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using static Mirror.Examples.CharacterSelection.NetworkManagerCharacterSelection;

namespace Mirror.Examples.CharacterSelection
{
{
public class CanvasReferencer : MonoBehaviour
{
// Make sure to attach these Buttons in the Inspector
Expand All @@ -25,7 +25,7 @@ private void Start()
characterData = CharacterData.characterDataSingleton;
if (characterData == null)
{
Debug.Log("Add CharacterData prefab singleton into the scene.");
Debug.Log("Add CharacterData prefab Instance into the scene.");
return;
}

Expand Down Expand Up @@ -73,7 +73,7 @@ public void ButtonGo()
{
createCharacterMessage = _characterMessage
};
NetworkManagerCharacterSelection.singleton.ReplaceCharacter(replaceCharacterMessage);
NetworkManagerCharacterSelection.Instance.ReplaceCharacter(replaceCharacterMessage);
sceneReferencer.CloseCharacterSelection();
}
else
Expand Down Expand Up @@ -191,4 +191,4 @@ public void LoadData()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using Mirror.Examples.AssignAuthority;
using UnityEngine;
using Random = UnityEngine.Random;

namespace Mirror.Examples.CharacterSelection
{
Expand All @@ -11,7 +14,10 @@ public class NetworkManagerCharacterSelection : NetworkManager
// Either of these allow selecting character after spawning in too.
public bool SpawnAsCharacter = true;

public static new NetworkManagerCharacterSelection singleton => (NetworkManagerCharacterSelection)NetworkManager.singleton;
// DEPRECATED 2025-07-29
[Obsolete("Use .instance instead of .singleton")]
public static new NetworkManagerCharacterSelection singleton => Instance;
public static new NetworkManagerCharacterSelection Instance => (NetworkManagerCharacterSelection)NetworkManager.Instance;
private CharacterData characterData;

public override void Awake()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Examples/Chat/Scripts/ChatAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void OnAuthResponseMessage(AuthResponseMessage msg)

// Authentication has been rejected
// StopHost works for both host client and remote clients
NetworkManager.singleton.StopHost();
NetworkManager.Instance.StopHost();

// Do this AFTER StopHost so it doesn't get cleared / hidden by OnClientDisconnect
LoginUI.instance.errorText.text = msg.message;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Examples/Chat/Scripts/ChatUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void ExitButtonOnClick()
{
// StopHost calls both StopClient and StopServer
// StopServer does nothing on remote clients
NetworkManager.singleton.StopHost();
NetworkManager.Instance.StopHost();
}

// Called by UI element MessageField.OnValueChanged
Expand Down
Loading