From 96eba51be9661bbfa8f274e8e849480ee7cde7a2 Mon Sep 17 00:00:00 2001 From: Soraphis Date: Wed, 19 Jul 2023 17:38:39 +0000 Subject: [PATCH] fix: clearing event registrations when changing playmode stage. --- Packages/Core/Runtime/Events/AtomEvent.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Packages/Core/Runtime/Events/AtomEvent.cs b/Packages/Core/Runtime/Events/AtomEvent.cs index 0c52aadf..43a9b37c 100644 --- a/Packages/Core/Runtime/Events/AtomEvent.cs +++ b/Packages/Core/Runtime/Events/AtomEvent.cs @@ -67,6 +67,7 @@ namespace UnityAtoms foreach (var instance in _instances) { instance._replayBuffer.Clear(); + instance.UnregisterAll(); } } else if (state == PlayModeStateChange.EnteredPlayMode) @@ -74,6 +75,7 @@ namespace UnityAtoms foreach (var instance in _instances) { instance._replayBuffer.Clear(); + instance.UnregisterAll(); } } } @@ -82,14 +84,7 @@ namespace UnityAtoms private void OnDisable() { // Clear all delegates when exiting play mode - if (_onEvent != null) - { - var invocationList = _onEvent.GetInvocationList(); - foreach (var d in invocationList) - { - _onEvent -= (Action)d; - } - } + UnregisterAll(); } ///