Add preserving local changes to model prefab objects when reimporting
#2275
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#if COMPILE_WITH_ASSETS_IMPORTER
|
#if COMPILE_WITH_ASSETS_IMPORTER
|
||||||
|
|
||||||
#include "Engine/Core/Log.h"
|
#include "Engine/Core/Log.h"
|
||||||
|
#include "Engine/Core/Cache.h"
|
||||||
#include "Engine/Core/Collections/Sorting.h"
|
#include "Engine/Core/Collections/Sorting.h"
|
||||||
#include "Engine/Core/Collections/ArrayExtensions.h"
|
#include "Engine/Core/Collections/ArrayExtensions.h"
|
||||||
#include "Engine/Serialization/MemoryWriteStream.h"
|
#include "Engine/Serialization/MemoryWriteStream.h"
|
||||||
@@ -765,6 +766,7 @@ CreateAssetResult ImportModel::CreatePrefab(CreateAssetContext& context, ModelDa
|
|||||||
// Link with object from prefab (if reimporting)
|
// Link with object from prefab (if reimporting)
|
||||||
if (prefab)
|
if (prefab)
|
||||||
{
|
{
|
||||||
|
rapidjson_flax::StringBuffer buffer;
|
||||||
for (Actor* a : nodeActors)
|
for (Actor* a : nodeActors)
|
||||||
{
|
{
|
||||||
for (const auto& i : prefab->ObjectsCache)
|
for (const auto& i : prefab->ObjectsCache)
|
||||||
@@ -775,6 +777,32 @@ CreateAssetResult ImportModel::CreatePrefab(CreateAssetContext& context, ModelDa
|
|||||||
if (o->GetName() != a->GetName()) // Name match
|
if (o->GetName() != a->GetName()) // Name match
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Preserve local changes made in the prefab
|
||||||
|
{
|
||||||
|
// Serialize
|
||||||
|
buffer.Clear();
|
||||||
|
CompactJsonWriter writer(buffer);
|
||||||
|
writer.StartObject();
|
||||||
|
const void* defaultInstance = o->GetType().GetDefaultInstance();
|
||||||
|
o->Serialize(writer, defaultInstance);
|
||||||
|
writer.EndObject();
|
||||||
|
|
||||||
|
// Parse json
|
||||||
|
rapidjson_flax::Document document;
|
||||||
|
document.Parse(buffer.GetString(), buffer.GetSize());
|
||||||
|
|
||||||
|
// Strip unwanted data
|
||||||
|
document.RemoveMember("ID");
|
||||||
|
document.RemoveMember("ParentID");
|
||||||
|
document.RemoveMember("PrefabID");
|
||||||
|
document.RemoveMember("PrefabObjectID");
|
||||||
|
document.RemoveMember("Name");
|
||||||
|
|
||||||
|
// Deserialize object
|
||||||
|
auto modifier = Cache::ISerializeModifier.Get();
|
||||||
|
a->Deserialize(document, &*modifier);
|
||||||
|
}
|
||||||
|
|
||||||
// Mark as this object already exists in prefab so will be preserved when updating it
|
// Mark as this object already exists in prefab so will be preserved when updating it
|
||||||
a->LinkPrefab(o->GetPrefabID(), o->GetPrefabObjectID());
|
a->LinkPrefab(o->GetPrefabID(), o->GetPrefabObjectID());
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user