Merge pull request #378 from aws-lumberyard-dev/Prefab/CreatePrefab

LYN-3159 - Fixed an assert during loading a level with prefabs that had patches on them
This commit is contained in:
srikappa-amzn
2021-04-28 15:22:05 -07:00
committed by GitHub
3 changed files with 13 additions and 16 deletions
@@ -108,11 +108,9 @@ namespace AzToolsFramework
m_targetTemplateId = id;
}
void Link::SetTemplatePatches(const PrefabDomValue& patches)
void Link::SetLinkDom(const PrefabDomValue& linkDom)
{
PrefabDom newPatches;
newPatches.CopyFrom(patches, newPatches.GetAllocator());
m_linkDom.Swap(newPatches);
m_linkDom.CopyFrom(linkDom, m_linkDom.GetAllocator());
}
void Link::SetInstanceName(const char* instanceName)
@@ -47,7 +47,7 @@ namespace AzToolsFramework
void SetSourceTemplateId(TemplateId id);
void SetTargetTemplateId(TemplateId id);
void SetTemplatePatches(const PrefabDomValue& patches);
void SetLinkDom(const PrefabDomValue& linkDom);
void SetInstanceName(const char* instanceName);
bool IsValid() const;
@@ -782,22 +782,21 @@ namespace AzToolsFramework
link.SetInstanceName(instanceName.data());
PrefabDomValue& instance = instanceIterator->value;
AZ_Assert(instance.IsObject(), "Nested instance DOM provided is not a valid JSON object.");
PrefabDomValueReference sourceTemplateName = PrefabDomUtils::FindPrefabDomValue(instance, PrefabDomUtils::SourceName);
AZ_Assert(sourceTemplateName, "Couldn't find source template name in the DOM of the nested instance while creating a link.");
AZ_Assert(
sourceTemplateName->get() == sourceTemplate.GetFilePath().c_str(),
"The name of the source template in the nested instance DOM does not match the name of the source template already loaded");
PrefabDomValueReference patchesReference = PrefabDomUtils::FindPrefabDomValue(instance, PrefabDomUtils::PatchesName);
if (!patchesReference.has_value())
if (patchesReference.has_value())
{
PrefabDom& newLinkDom = link.GetLinkDom();
newLinkDom.SetObject();
newLinkDom.AddMember(rapidjson::StringRef(PrefabDomUtils::SourceName),
rapidjson::StringRef(sourceTemplate.GetFilePath().c_str()), newLinkDom.GetAllocator());
}
else
{
link.SetTemplatePatches(patchesReference->get());
AZ_Assert(patchesReference->get().IsArray(), "Patches in the nested instance DOM are not represented as an array.");
}
link.SetLinkDom(instance);
if (!link.UpdateTarget())
{
AZ_Error("Prefab", false,