Fix scene object reference serialization in Visual Script properties

#3136
This commit is contained in:
Wojtek Figat
2025-02-17 10:23:07 +01:00
parent 67db774a2f
commit 8b1d678f2e

View File

@@ -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<SceneObject>((ScriptingObject*)a);
auto* bSceneObject = ScriptingObject::Cast<SceneObject>((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);