Fix incorrect prefab serialization to correctly handle diff on object references to prefab objects
#3136
This commit is contained in:
@@ -41,7 +41,7 @@ void ChangeIds(rapidjson_flax::Value& obj, rapidjson_flax::Document& document, c
|
||||
'0','0','0','0','0','0','0','0','0','0',
|
||||
'0','0','0','0','0','0','0','0','0','0',
|
||||
'0','0'
|
||||
// @formatter:on
|
||||
// @formatter:on
|
||||
};
|
||||
static const char* digits = "0123456789abcdef";
|
||||
uint32 n = value.A;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "Engine/Scripting/ManagedCLR/MClass.h"
|
||||
#include "Engine/Scripting/ScriptingObjectReference.h"
|
||||
#include "Engine/Content/Asset.h"
|
||||
#include "Engine/Level/SceneObject.h"
|
||||
#include "Engine/Utilities/Encryption.h"
|
||||
|
||||
void ISerializable::DeserializeIfExists(DeserializeStream& stream, const char* memberName, ISerializeModifier* modifier)
|
||||
@@ -789,4 +790,16 @@ void Serialization::Deserialize(ISerializable::DeserializeStream& stream, Matrix
|
||||
DESERIALIZE_HELPER(stream, "M44", v.M44, 0);
|
||||
}
|
||||
|
||||
bool Serialization::ShouldSerialize(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();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#undef DESERIALIZE_HELPER
|
||||
|
||||
@@ -441,10 +441,12 @@ namespace Serialization
|
||||
|
||||
// Scripting Object
|
||||
|
||||
FLAXENGINE_API bool ShouldSerialize(const SceneObject* v, const SceneObject* other);
|
||||
|
||||
template<typename T>
|
||||
inline typename TEnableIf<TIsBaseOf<ScriptingObject, T>::Value, bool>::Type ShouldSerialize(const T*& v, const void* otherObj)
|
||||
{
|
||||
return !otherObj || v != *(T**)otherObj;
|
||||
return !otherObj || v != *(const T**)otherObj;
|
||||
}
|
||||
template<typename T>
|
||||
inline typename TEnableIf<TIsBaseOf<ScriptingObject, T>::Value>::Type Serialize(ISerializable::SerializeStream& stream, const T*& v, const void* otherObj)
|
||||
@@ -460,12 +462,18 @@ namespace Serialization
|
||||
v = (T*)::FindObject(id, T::GetStaticClass());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline typename TEnableIf<TIsBaseOf<SceneObject, T>::Value, bool>::Type ShouldSerialize(const T*& v, const void* otherObj)
|
||||
{
|
||||
return !otherObj || ShouldSerialize((const SceneObject*)v, *(const SceneObject**)otherObj);
|
||||
}
|
||||
|
||||
// Scripting Object Reference
|
||||
|
||||
template<typename T>
|
||||
inline bool ShouldSerialize(const ScriptingObjectReference<T>& v, const void* otherObj)
|
||||
{
|
||||
return !otherObj || v.Get() != ((ScriptingObjectReference<T>*)otherObj)->Get();
|
||||
return !otherObj || ShouldSerialize(v.Get(), ((ScriptingObjectReference<T>*)otherObj)->Get());
|
||||
}
|
||||
template<typename T>
|
||||
inline void Serialize(ISerializable::SerializeStream& stream, const ScriptingObjectReference<T>& v, const void* otherObj)
|
||||
@@ -486,7 +494,7 @@ namespace Serialization
|
||||
template<typename T>
|
||||
inline bool ShouldSerialize(const SoftObjectReference<T>& v, const void* otherObj)
|
||||
{
|
||||
return !otherObj || v.Get() != ((SoftObjectReference<T>*)otherObj)->Get();
|
||||
return !otherObj || ShouldSerialize(v.Get(), ((SoftObjectReference<T>*)otherObj)->Get());
|
||||
}
|
||||
template<typename T>
|
||||
inline void Serialize(ISerializable::SerializeStream& stream, const SoftObjectReference<T>& v, const void* otherObj)
|
||||
|
||||
Reference in New Issue
Block a user