Resolving links in the Prefab Processing Stack now also makes sure that entity ids of aliased entities are appropriately unique or match.
Signed-off-by: AMZN-koppersr <82230785+AMZN-koppersr@users.noreply.github.com>
This commit is contained in:
+24
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Component/EntityUtils.h>
|
||||
#include <AzFramework/Spawnable/Spawnable.h>
|
||||
#include <AzToolsFramework/Prefab/Instance/InstanceEntityMapperInterface.h>
|
||||
#include <AzToolsFramework/Prefab/Spawnable/PrefabProcessorContext.h>
|
||||
@@ -253,6 +254,29 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils
|
||||
|
||||
// Register the dependency between the two spawnables.
|
||||
RegisterProductAssetDependency(source->m_spawnable.GetId(), target->m_spawnable.GetId(), loadBehavior);
|
||||
|
||||
// Patch up all entity ids so the alias points to the same entity id if needed.
|
||||
switch (alias.m_aliasType)
|
||||
{
|
||||
case AzFramework::Spawnable::EntityAliasType::Original:
|
||||
continue;
|
||||
case AzFramework::Spawnable::EntityAliasType::Disable:
|
||||
continue;
|
||||
case AzFramework::Spawnable::EntityAliasType::Replace:
|
||||
break; // Requires entity id for alias in source and target spawnable matches.
|
||||
case AzFramework::Spawnable::EntityAliasType::Additional:
|
||||
continue;
|
||||
case AzFramework::Spawnable::EntityAliasType::Merge:
|
||||
break; // Requires entity id for alias in source and target spawnable matches.
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
auto entityIdMapper = [source, target](const AZ::EntityId& originalId, bool /*isEntityId*/) -> AZ::EntityId
|
||||
{
|
||||
return originalId == target->m_index ? source->m_index : originalId;
|
||||
};
|
||||
AZ::EntityUtils::ReplaceEntityIdsAndEntityRefs(&target->m_spawnable, entityIdMapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -85,9 +85,9 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
|
||||
AZ_Assert(
|
||||
entityData.has_value(), "SpawnbleUtils were unable to locate entity '%.*s' in Instance '%s' for replacing.",
|
||||
AZ_STRING_ARG(alias), source.GetTemplateSourcePath().c_str());
|
||||
auto placeholder = AZStd::make_unique<AZ::Entity>(entityData->get().GetId(), entityData->get().GetName());
|
||||
// A new entity id can be used for the placeholder as `ReplaceEntity` will swap the entity ids.
|
||||
auto placeholder = AZStd::make_unique<AZ::Entity>(AZ::Entity::MakeId(), entityData->get().GetName());
|
||||
AZStd::unique_ptr<AZ::Entity> result = instance->ReplaceEntity(AZStd::move(placeholder), alias);
|
||||
result->SetId(AZ::Entity::MakeId());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user