Skip to content

Commit 27282b4

Browse files
committed
Fixed the existing instance being deleted in Awake
Replaced `else` with `else if (instance != this)` as a condition for the instance to be deleted in Awake. This fixes a really weird bug where if singleton was used in the editor and then again in play mode, it would delete the original instance and create a new one. Closes #21
1 parent 9416bf6 commit 27282b4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Runtime/Scripts/MonoSingleton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected virtual void Awake()
7272
// Initialize existing instance
7373
InitializeSingleton();
7474
}
75-
else
75+
else if (instance != this)
7676
{
7777

7878
// Destory duplicates
@@ -147,4 +147,4 @@ public static void DestroyInstance()
147147

148148
#endregion
149149
}
150-
}
150+
}

0 commit comments

Comments
 (0)