Skip to content

Commit 8461a96

Browse files
authored
Merge pull request #65 from jaglitegrann/bug/NetworkedManager-singelton-gets-null-when-other-instanced-is-removed
Fix a bug that made NetworkedManager be set to null when destroying a…
2 parents c45e74e + cf64fed commit 8461a96

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ public bool IsClientConnected
148148
/// The callback to invoke once the server is ready
149149
/// </summary>
150150
public Action OnServerStarted = null;
151+
/// <summary>
152+
/// Wheter or not this NetworkedManager is an multiple instance of the singleton about to be removed.
153+
/// </summary>
154+
private bool isMultipleInstance = false;
151155
public delegate void ConnectionApprovedDelegate(uint clientId, int prefabId, bool approved, Vector3 position, Quaternion rotation);
152156
/// <summary>
153157
/// The callback to invoke during connection approval
@@ -646,7 +650,8 @@ private void OnEnable()
646650
if (singleton != null)
647651
{
648652
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("Multiple NetworkingManagers");
649-
Destroy(this);
653+
this.isMultipleInstance = true;
654+
Destroy(this.gameObject);
650655
return;
651656
}
652657
_singleton = this;
@@ -658,8 +663,10 @@ private void OnEnable()
658663

659664
private void OnDestroy()
660665
{
661-
_singleton = null;
662-
Shutdown();
666+
if (!isMultipleInstance) {
667+
_singleton = null;
668+
Shutdown();
669+
}
663670
}
664671

665672
private void Shutdown()

0 commit comments

Comments
 (0)