From 3aa06a70a1f488aa2b9c90465a387201da38a6be Mon Sep 17 00:00:00 2001 From: Simon Bucher Date: Sun, 25 Apr 2021 16:59:21 +0200 Subject: [PATCH] Fix ChangedOnOnEnable not triggered When using an Event Reference Listener with a variable, GetOrCreateEvent() is sometimes called after TriggerInitialEvents(). This commit solves this issue. --- Packages/Core/Runtime/Variables/AtomVariable.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Packages/Core/Runtime/Variables/AtomVariable.cs b/Packages/Core/Runtime/Variables/AtomVariable.cs index e4abf2b6..6a083910 100644 --- a/Packages/Core/Runtime/Variables/AtomVariable.cs +++ b/Packages/Core/Runtime/Variables/AtomVariable.cs @@ -179,12 +179,18 @@ namespace UnityAtoms /// public void TriggerInitialEvents() { - if (Changed != null && _triggerChangedOnOnEnable) + if (_triggerChangedOnOnEnable) { + if (Changed == null) + GetOrCreateEvent(); + Changed.Raise(Value); } - if (ChangedWithHistory != null && _triggerChangedWithHistoryOnOnEnable) + if (_triggerChangedWithHistoryOnOnEnable) { + if(ChangedWithHistory == null) + GetOrCreateEvent(); + var pair = default(P); pair.Item1 = _value; pair.Item2 = _oldValue;