From 27282b4edf460ab286e2fc72a0d88e55df3fa112 Mon Sep 17 00:00:00 2001 From: nnra6864 Date: Mon, 15 Sep 2025 12:55:11 +0200 Subject: [PATCH] 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 --- Runtime/Scripts/MonoSingleton.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/Scripts/MonoSingleton.cs b/Runtime/Scripts/MonoSingleton.cs index 314aded..f27273d 100644 --- a/Runtime/Scripts/MonoSingleton.cs +++ b/Runtime/Scripts/MonoSingleton.cs @@ -72,7 +72,7 @@ protected virtual void Awake() // Initialize existing instance InitializeSingleton(); } - else + else if (instance != this) { // Destory duplicates @@ -147,4 +147,4 @@ public static void DestroyInstance() #endregion } -} \ No newline at end of file +}