Always store LinkIds during prefab instance serialization except when saving to disk (#7444)
* Always store prefab instance linkIds to DOM except for saving to disk Signed-off-by: srikappa-amzn <82230713+srikappa-amzn@users.noreply.github.com> * Added more checks to remove linkIds from templates Signed-off-by: srikappa-amzn <82230713+srikappa-amzn@users.noreply.github.com> * Remove additional check to remove LinkId during template update Signed-off-by: srikappa-amzn <82230713+srikappa-amzn@users.noreply.github.com>
This commit is contained in:
@@ -73,7 +73,7 @@ namespace AzToolsFramework
|
||||
settings.m_keepDefaults = true;
|
||||
}
|
||||
|
||||
if ((flags & StoreFlags::StoreLinkIds) != StoreFlags::None)
|
||||
if ((flags & StoreFlags::StripLinkIds) != StoreFlags::StripLinkIds)
|
||||
{
|
||||
settings.m_metadata.Create<LinkIdMetadata>();
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace AzToolsFramework
|
||||
|
||||
//! We do not save linkIds to file. However when loading a level we want to temporarily save
|
||||
//! linkIds to instance dom so any nested prefabs will have linkIds correctly set.
|
||||
StoreLinkIds = 1 << 1
|
||||
StripLinkIds = 1 << 1
|
||||
};
|
||||
AZ_DEFINE_ENUM_BITWISE_OPERATORS(StoreFlags);
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace AzToolsFramework
|
||||
}
|
||||
|
||||
PrefabDom storedPrefabDom(&loadedTemplateDom->get().GetAllocator());
|
||||
if (!PrefabDomUtils::StoreInstanceInPrefabDom(loadedPrefabInstance, storedPrefabDom, PrefabDomUtils::StoreFlags::StoreLinkIds))
|
||||
if (!PrefabDomUtils::StoreInstanceInPrefabDom(loadedPrefabInstance, storedPrefabDom))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -359,7 +359,7 @@ namespace AzToolsFramework
|
||||
|
||||
PrefabDom storedPrefabDom(&savingTemplateDom->get().GetAllocator());
|
||||
if (!PrefabDomUtils::StoreInstanceInPrefabDom(savingPrefabInstance, storedPrefabDom,
|
||||
PrefabDomUtils::StoreFlags::StripDefaultValues))
|
||||
PrefabDomUtils::StoreFlags::StripDefaultValues | PrefabDomUtils::StoreFlags::StripLinkIds))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ namespace AzToolsFramework
|
||||
|
||||
// Update the template of the instance since the entities are modified since the template creation.
|
||||
Prefab::PrefabDom serializedInstance;
|
||||
if (Prefab::PrefabDomUtils::StoreInstanceInPrefabDom(instanceToCreate->get(), serializedInstance))
|
||||
if (m_instanceToTemplateInterface->GenerateDomForInstance(serializedInstance, instanceToCreate->get()))
|
||||
{
|
||||
m_prefabSystemComponentInterface->UpdatePrefabTemplate(instanceToCreate->get().GetTemplateId(), serializedInstance);
|
||||
}
|
||||
|
||||
@@ -163,17 +163,21 @@ namespace AzToolsFramework
|
||||
|
||||
void PrefabSystemComponent::PropagateTemplateChanges(TemplateId templateId, InstanceOptionalConstReference instanceToExclude)
|
||||
{
|
||||
auto templateIdToLinkIdsIterator = m_templateToLinkIdsMap.find(templateId);
|
||||
if (templateIdToLinkIdsIterator != m_templateToLinkIdsMap.end())
|
||||
TemplateReference findTemplateResult = FindTemplate(templateId);
|
||||
if (findTemplateResult.has_value())
|
||||
{
|
||||
// We need to initialize a queue here because once all linked instances of a template are updated,
|
||||
// we will find all the linkIds corresponding to the updated template and add them to this queue again.
|
||||
AZStd::queue<LinkIds> linkIdsToUpdateQueue;
|
||||
linkIdsToUpdateQueue.push(LinkIds(templateIdToLinkIdsIterator->second.begin(),
|
||||
templateIdToLinkIdsIterator->second.end()));
|
||||
UpdateLinkedInstances(linkIdsToUpdateQueue);
|
||||
auto templateIdToLinkIdsIterator = m_templateToLinkIdsMap.find(templateId);
|
||||
if (templateIdToLinkIdsIterator != m_templateToLinkIdsMap.end())
|
||||
{
|
||||
// We need to initialize a queue here because once all linked instances of a template are updated,
|
||||
// we will find all the linkIds corresponding to the updated template and add them to this queue again.
|
||||
AZStd::queue<LinkIds> linkIdsToUpdateQueue;
|
||||
linkIdsToUpdateQueue.push(
|
||||
LinkIds(templateIdToLinkIdsIterator->second.begin(), templateIdToLinkIdsIterator->second.end()));
|
||||
UpdateLinkedInstances(linkIdsToUpdateQueue);
|
||||
}
|
||||
UpdatePrefabInstances(templateId, instanceToExclude);
|
||||
}
|
||||
UpdatePrefabInstances(templateId, instanceToExclude);
|
||||
}
|
||||
|
||||
void PrefabSystemComponent::UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom)
|
||||
|
||||
@@ -256,7 +256,7 @@ namespace AzToolsFramework
|
||||
return;
|
||||
}
|
||||
|
||||
PrefabDomReference sourceDom = sourceTemplate->get().GetPrefabDom();
|
||||
PrefabDom& sourceDom = sourceTemplate->get().GetPrefabDom();
|
||||
|
||||
//use instance pointer to reach position
|
||||
PrefabDomValueReference instanceDomRef = link->get().GetLinkedInstanceDom();
|
||||
@@ -274,16 +274,14 @@ namespace AzToolsFramework
|
||||
(result.GetOutcome() != AZ::JsonSerializationResult::Outcomes::PartialSkip),
|
||||
"Some of the patches are not successfully applied.");
|
||||
|
||||
//remove the link id placed into the instance
|
||||
auto linkIdIter = instanceDom.FindMember(PrefabDomUtils::LinkIdName);
|
||||
if (linkIdIter != instanceDom.MemberEnd())
|
||||
{
|
||||
instanceDom.RemoveMember(PrefabDomUtils::LinkIdName);
|
||||
}
|
||||
// Remove the link ids if present in the doms. We don't want any overrides to be created on top of linkIds because
|
||||
// linkIds are not persistent and will be created dynamically when prefabs are loaded into the editor.
|
||||
instanceDom.RemoveMember(PrefabDomUtils::LinkIdName);
|
||||
sourceDom.RemoveMember(PrefabDomUtils::LinkIdName);
|
||||
|
||||
//we use this to diff our copy against the vanilla template (source template)
|
||||
PrefabDom patchLink;
|
||||
m_instanceToTemplateInterface->GeneratePatch(patchLink, sourceDom->get(), instanceDom);
|
||||
m_instanceToTemplateInterface->GeneratePatch(patchLink, sourceDom, instanceDom);
|
||||
|
||||
// Create a copy of patchLink by providing the allocator of m_linkDomNext so that the patch doesn't become invalid when
|
||||
// the patch goes out of scope in this function.
|
||||
|
||||
Reference in New Issue
Block a user