Fixing a crash when unparenting prefab instance in a new level
Signed-off-by: mnaumov <mnaumov@amazon.com>
This commit is contained in:
+1
-1
@@ -202,7 +202,7 @@ namespace AzToolsFramework
|
||||
m_rootInstance->SetTemplateId(templateId);
|
||||
m_rootInstance->SetTemplateSourcePath(m_loaderInterface->GenerateRelativePath(filename));
|
||||
m_rootInstance->SetContainerEntityName("Level");
|
||||
m_prefabSystemComponent->PropagateTemplateChanges(templateId);
|
||||
m_prefabSystemComponent->PropagateTemplateChangesDown(templateId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -482,22 +482,36 @@ namespace AzToolsFramework
|
||||
AZStd::unique_ptr<Instance>& sourceInstance, TemplateId targetTemplateId, UndoSystem::URSequencePoint* undoBatch)
|
||||
{
|
||||
LinkReference nestedInstanceLink = m_prefabSystemComponentInterface->FindLink(sourceInstance->GetLinkId());
|
||||
AZ_Assert(
|
||||
nestedInstanceLink.has_value(),
|
||||
"A valid link was not found for one of the instances provided as input for the CreatePrefab operation.");
|
||||
if (!nestedInstanceLink)
|
||||
{
|
||||
AZ_Assert(
|
||||
false,
|
||||
"A valid link was not found for one of the instances provided as input for the CreatePrefab operation.");
|
||||
return;
|
||||
}
|
||||
|
||||
PrefabDomReference nestedInstanceLinkDom = nestedInstanceLink->get().GetLinkDom();
|
||||
AZ_Assert(
|
||||
nestedInstanceLinkDom.has_value(),
|
||||
"A valid DOM was not found for the link corresponding to one of the instances provided as input for the "
|
||||
"CreatePrefab operation.");
|
||||
|
||||
if (!nestedInstanceLinkDom)
|
||||
{
|
||||
AZ_Assert(
|
||||
false,
|
||||
"A valid DOM was not found for the link corresponding to one of the instances provided as input for the "
|
||||
"CreatePrefab operation.");
|
||||
return;
|
||||
}
|
||||
|
||||
PrefabDomValueReference nestedInstanceLinkPatches =
|
||||
PrefabDomUtils::FindPrefabDomValue(nestedInstanceLinkDom->get(), PrefabDomUtils::PatchesName);
|
||||
AZ_Assert(
|
||||
nestedInstanceLinkPatches.has_value(),
|
||||
"A valid DOM for patches was not found for the link corresponding to one of the instances provided as input for the "
|
||||
"CreatePrefab operation.");
|
||||
|
||||
if (!nestedInstanceLinkPatches)
|
||||
{
|
||||
AZ_Assert(
|
||||
false,
|
||||
"A valid DOM for patches was not found for the link corresponding to one of the instances provided as input for the "
|
||||
"CreatePrefab operation.");
|
||||
return;
|
||||
}
|
||||
|
||||
PrefabDom patchesCopyForUndoSupport;
|
||||
patchesCopyForUndoSupport.CopyFrom(nestedInstanceLinkPatches->get(), patchesCopyForUndoSupport.GetAllocator());
|
||||
|
||||
@@ -153,6 +153,24 @@ namespace AzToolsFramework
|
||||
}
|
||||
}
|
||||
|
||||
void PrefabSystemComponent::PropagateTemplateChangesDown(TemplateId templateId, InstanceOptionalReference instanceToExclude)
|
||||
{
|
||||
PropagateTemplateChanges(templateId, instanceToExclude);
|
||||
|
||||
auto templateIterator = m_templateIdMap.find(templateId);
|
||||
if (templateIterator != m_templateIdMap.end())
|
||||
{
|
||||
for (LinkId linkId : templateIterator->second.GetLinks())
|
||||
{
|
||||
auto linkIterator = m_linkIdMap.find(linkId);
|
||||
if (linkIterator != m_linkIdMap.end())
|
||||
{
|
||||
PropagateTemplateChangesDown(linkIterator->second.GetSourceTemplateId(), instanceToExclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PrefabSystemComponent::UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom)
|
||||
{
|
||||
auto templateToUpdate = FindTemplate(templateId);
|
||||
|
||||
@@ -213,6 +213,8 @@ namespace AzToolsFramework
|
||||
|
||||
void PropagateTemplateChanges(TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override;
|
||||
|
||||
void PropagateTemplateChangesDown(TemplateId templateIdd, InstanceOptionalReference instanceToExclude = AZStd::nullopt) override;
|
||||
|
||||
/**
|
||||
* Updates all Instances owned by a Template.
|
||||
*
|
||||
|
||||
+2
@@ -53,6 +53,8 @@ namespace AzToolsFramework
|
||||
virtual PrefabDom& FindTemplateDom(TemplateId templateId) = 0;
|
||||
virtual void UpdatePrefabTemplate(TemplateId templateId, const PrefabDom& updatedDom) = 0;
|
||||
virtual void PropagateTemplateChanges(TemplateId templateId, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0;
|
||||
//! Propagates template changes recursively down to its dependents
|
||||
virtual void PropagateTemplateChangesDown(TemplateId templateIdd, InstanceOptionalReference instanceToExclude = AZStd::nullopt) = 0;
|
||||
|
||||
virtual AZStd::unique_ptr<Instance> InstantiatePrefab(AZ::IO::PathView filePath) = 0;
|
||||
virtual AZStd::unique_ptr<Instance> InstantiatePrefab(const TemplateId& templateId) = 0;
|
||||
|
||||
Reference in New Issue
Block a user