diff --git a/Source/Engine/Serialization/Serialization.cpp b/Source/Engine/Serialization/Serialization.cpp index 45b03a07c..a3dfc6ffa 100644 --- a/Source/Engine/Serialization/Serialization.cpp +++ b/Source/Engine/Serialization/Serialization.cpp @@ -790,14 +790,14 @@ void Serialization::Deserialize(ISerializable::DeserializeStream& stream, Matrix DESERIALIZE_HELPER(stream, "M44", v.M44, 0); } -bool Serialization::ShouldSerialize(const SceneObject* v, const SceneObject* other) +bool Serialization::ShouldSerializeRef(const SceneObject* v, const SceneObject* other) { bool result = v != other; if (result && v && other && v->HasPrefabLink() && other->HasPrefabLink()) { // Special case when saving reference to prefab object and the objects are different but the point to the same prefab object // In that case, skip saving reference as it's defined in prefab (will be populated via IdsMapping during deserialization) - result &= v->GetPrefabObjectID() != other->GetPrefabObjectID(); + result = v->GetPrefabObjectID() != other->GetPrefabObjectID(); } return result; } diff --git a/Source/Engine/Serialization/Serialization.h b/Source/Engine/Serialization/Serialization.h index b8167e8d2..d3205ad83 100644 --- a/Source/Engine/Serialization/Serialization.h +++ b/Source/Engine/Serialization/Serialization.h @@ -448,15 +448,20 @@ namespace Serialization // Scripting Object - FLAXENGINE_API bool ShouldSerialize(const SceneObject* v, const SceneObject* other); + inline bool ShouldSerializeRef(const ScriptingObject* v, const ScriptingObject* other) + { + return v != other; + } + + FLAXENGINE_API bool ShouldSerializeRef(const SceneObject* v, const SceneObject* other); template - inline typename TEnableIf::Value, bool>::Type ShouldSerialize(const T*& v, const void* otherObj) + inline typename TEnableIf, TNot>>::Value, bool>::Type ShouldSerialize(const T* v, const void* otherObj) { return !otherObj || v != *(const T**)otherObj; } template - inline typename TEnableIf::Value>::Type Serialize(ISerializable::SerializeStream& stream, const T*& v, const void* otherObj) + inline typename TEnableIf::Value>::Type Serialize(ISerializable::SerializeStream& stream, const T* v, const void* otherObj) { stream.Guid(v ? v->GetID() : Guid::Empty); } @@ -470,9 +475,9 @@ namespace Serialization } template - inline typename TEnableIf::Value, bool>::Type ShouldSerialize(const T*& v, const void* otherObj) + inline typename TEnableIf::Value, bool>::Type ShouldSerialize(const T* v, const void* otherObj) { - return !otherObj || ShouldSerialize((const SceneObject*)v, *(const SceneObject**)otherObj); + return !otherObj || ShouldSerializeRef((const SceneObject*)v, *(const SceneObject**)otherObj); } // Scripting Object Reference @@ -480,7 +485,7 @@ namespace Serialization template inline bool ShouldSerialize(const ScriptingObjectReference& v, const void* otherObj) { - return !otherObj || ShouldSerialize(v.Get(), ((ScriptingObjectReference*)otherObj)->Get()); + return !otherObj || ShouldSerializeRef(v.Get(), ((ScriptingObjectReference*)otherObj)->Get()); } template inline void Serialize(ISerializable::SerializeStream& stream, const ScriptingObjectReference& v, const void* otherObj) @@ -501,7 +506,7 @@ namespace Serialization template inline bool ShouldSerialize(const SoftObjectReference& v, const void* otherObj) { - return !otherObj || ShouldSerialize(v.Get(), ((SoftObjectReference*)otherObj)->Get()); + return !otherObj || ShouldSerializeRef(v.Get(), ((SoftObjectReference*)otherObj)->Get()); } template inline void Serialize(ISerializable::SerializeStream& stream, const SoftObjectReference& v, const void* otherObj) diff --git a/Source/Engine/Serialization/SerializationFwd.h b/Source/Engine/Serialization/SerializationFwd.h index 84b51cb39..58ece7fda 100644 --- a/Source/Engine/Serialization/SerializationFwd.h +++ b/Source/Engine/Serialization/SerializationFwd.h @@ -80,7 +80,7 @@ class ISerializeModifier; // Explicit auto-cast for object pointer #define SERIALIZE_OBJ(name) \ - if (Serialization::ShouldSerialize((const ScriptingObject*&)name, other ? &other->name : nullptr)) \ + if (Serialization::ShouldSerialize(name, decltype(name)(other ? &other->name : nullptr))) \ { \ stream.JKEY(#name); \ Serialization::Serialize(stream, (const ScriptingObject*&)name, other ? &other->name : nullptr); \