Skip to content

Commit ad9e7bd

Browse files
committed
Cleaned up multiple instance checks for NetworkingManager
1 parent 8fffd5d commit ad9e7bd

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ public class NetworkingManager : MonoBehaviour
8888
/// </summary>
8989
public Action OnServerStarted = null;
9090
/// <summary>
91-
/// Wheter or not this NetworkedManager is an multiple instance of the singleton about to be removed.
92-
/// </summary>
93-
private bool isMultipleInstance = false;
94-
/// <summary>
9591
/// Delegate type called when connection has been approved
9692
/// </summary>
9793
/// <param name="clientId">The clientId of the approved client</param>
@@ -596,25 +592,26 @@ public void StartHost(Vector3? pos = null, Quaternion? rot = null, int prefabId
596592

597593
private void OnEnable()
598594
{
599-
if (singleton != null)
595+
if (singleton != null && singleton != this)
600596
{
601-
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("Multiple NetworkingManagers");
602-
this.isMultipleInstance = true;
603597
Destroy(this.gameObject);
604-
return;
605598
}
606-
singleton = this;
607-
if (DontDestroy)
608-
DontDestroyOnLoad(gameObject);
609-
if (RunInBackground)
610-
Application.runInBackground = true;
599+
else
600+
{
601+
singleton = this;
602+
if (DontDestroy)
603+
DontDestroyOnLoad(gameObject);
604+
if (RunInBackground)
605+
Application.runInBackground = true;
606+
}
611607
}
612608

613609
private void OnDestroy()
614610
{
615-
if (!isMultipleInstance) {
611+
if (singleton != null && singleton == this)
612+
{
616613
singleton = null;
617-
Shutdown();
614+
Shutdown();
618615
}
619616
}
620617

0 commit comments

Comments
 (0)