From cc019520590428ec896fab37e0079a386036dec5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 11 Sep 2024 20:44:45 +0200 Subject: [PATCH] Fix Visject parameter values restore after script is saved in editor by using original value diff #2276 --- Source/Engine/Content/Assets/VisualScript.cpp | 8 +++++++- Source/Engine/Content/Assets/VisualScript.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Content/Assets/VisualScript.cpp b/Source/Engine/Content/Assets/VisualScript.cpp index 616fbe91a..4fd1718ab 100644 --- a/Source/Engine/Content/Assets/VisualScript.cpp +++ b/Source/Engine/Content/Assets/VisualScript.cpp @@ -1471,7 +1471,8 @@ Asset::LoadResult VisualScript::load() for (int32 i = 0; i < count; i++) { const int32 oldIndex = _oldParamsLayout.Find(Graph.Parameters[i].Identifier); - instanceParams[i] = oldIndex != -1 ? valuesCache[oldIndex] : Graph.Parameters[i].Value; + const bool useOldValue = oldIndex != -1 && valuesCache[oldIndex] != _oldParamsValues[i]; + instanceParams[i] = useOldValue ? valuesCache[oldIndex] : Graph.Parameters[i].Value; } } } @@ -1486,6 +1487,8 @@ Asset::LoadResult VisualScript::load() instanceParams[i] = Graph.Parameters[i].Value; } } + _oldParamsLayout.Clear(); + _oldParamsValues.Clear(); } #endif @@ -1499,15 +1502,18 @@ void VisualScript::unload(bool isReloading) { // Cache existing instanced parameters IDs to restore values after asset reload (params order might be changed but the IDs are stable) _oldParamsLayout.Resize(Graph.Parameters.Count()); + _oldParamsValues.Resize(Graph.Parameters.Count()); for (int32 i = 0; i < Graph.Parameters.Count(); i++) { auto& param = Graph.Parameters[i]; _oldParamsLayout[i] = param.Identifier; + _oldParamsValues[i] = param.Value; } } else { _oldParamsLayout.Clear(); + _oldParamsValues.Clear(); } #else _instances.Clear(); diff --git a/Source/Engine/Content/Assets/VisualScript.h b/Source/Engine/Content/Assets/VisualScript.h index 4fda11fef..be90f4a68 100644 --- a/Source/Engine/Content/Assets/VisualScript.h +++ b/Source/Engine/Content/Assets/VisualScript.h @@ -154,6 +154,7 @@ private: Array> _fields; #if USE_EDITOR Array _oldParamsLayout; + Array _oldParamsValues; #endif public: