From 8b1d678f2e104e33f19bdd21699779dd80f22f02 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 17 Feb 2025 10:23:07 +0100 Subject: [PATCH] Fix scene object reference serialization in Visual Script properties #3136 --- Source/Engine/Content/Assets/VisualScript.cpp | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Content/Assets/VisualScript.cpp b/Source/Engine/Content/Assets/VisualScript.cpp index b410d62f7..fa64e007c 100644 --- a/Source/Engine/Content/Assets/VisualScript.cpp +++ b/Source/Engine/Content/Assets/VisualScript.cpp @@ -19,6 +19,7 @@ #include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Utilities/StringConverter.h" #include "Engine/Threading/MainThreadTask.h" +#include "Engine/Level/SceneObject.h" #include "FlaxEngine.Gen.h" namespace @@ -40,6 +41,22 @@ namespace Log::Logger::Write(type, stack); Log::Logger::Write(type, TEXT("")); } + + bool SerializeValue(const Variant& a, const Variant& b) + { + bool result = a != b; + if (result) + { + // Special case for scene objects to handle prefab object references + auto* aSceneObject = ScriptingObject::Cast((ScriptingObject*)a); + auto* bSceneObject = ScriptingObject::Cast((ScriptingObject*)b); + if (aSceneObject && bSceneObject) + { + result = Serialization::ShouldSerialize(aSceneObject, bSceneObject); + } + } + return result; + } } #if VISUAL_SCRIPT_DEBUGGING @@ -1960,7 +1977,7 @@ void VisualScriptingBinaryModule::SerializeObject(JsonWriter& stream, ScriptingO auto& param = asset->Graph.Parameters[paramIndex]; auto& value = params[paramIndex]; auto& otherValue = otherParams->Value.Params[paramIndex]; - if (value != otherValue) + if (SerializeValue(value, otherValue)) { param.Identifier.ToString(idName, Guid::FormatType::N); stream.Key(idName, 32); @@ -1975,7 +1992,7 @@ void VisualScriptingBinaryModule::SerializeObject(JsonWriter& stream, ScriptingO auto& param = asset->Graph.Parameters[paramIndex]; auto& value = params[paramIndex]; auto& otherValue = param.Value; - if (value != otherValue) + if (SerializeValue(value, otherValue)) { param.Identifier.ToString(idName, Guid::FormatType::N); stream.Key(idName, 32);