From 761a77a4363deda44d79cf6e1f93bf80639c57bf Mon Sep 17 00:00:00 2001 From: srikappa Date: Mon, 17 May 2021 18:51:23 -0700 Subject: [PATCH] Avoid creating a new list for non-container top level entities --- .../Prefab/PrefabPublicHandler.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 9f466db520..e6bb8c7dee 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -63,7 +63,7 @@ namespace AzToolsFramework PrefabOperationResult PrefabPublicHandler::CreatePrefab(const AZStd::vector& entityIds, AZ::IO::PathView filePath) { - EntityList inputEntityList, topLevelEntities, topLevelNonContainerEntities; + EntityList inputEntityList, topLevelEntities; AZ::EntityId commonRootEntityId; InstanceOptionalReference commonRootEntityOwningInstance; PrefabOperationResult findCommonRootOutcome = FindCommonRootOwningInstance( @@ -73,14 +73,6 @@ namespace AzToolsFramework return findCommonRootOutcome; } - for (AZ::Entity* toplevelentity : topLevelEntities) - { - if (!IsInstanceContainerEntity(toplevelentity->GetId())) - { - topLevelNonContainerEntities.push_back(toplevelentity); - } - } - InstanceOptionalReference instanceToCreate; { // Initialize Undo Batch object @@ -132,9 +124,12 @@ namespace AzToolsFramework // Parent the non-container top level entities to the container entity. // Parenting the top level container entities will be done during the creation of links. - for (AZ::Entity* entity : topLevelNonContainerEntities) + for (AZ::Entity* topLevelEntity : topLevelEntities) { - AZ::TransformBus::Event(entity->GetId(), &AZ::TransformBus::Events::SetParent, containerEntityId); + if (!IsInstanceContainerEntity(topLevelEntity->GetId())) + { + AZ::TransformBus::Event(topLevelEntity->GetId(), &AZ::TransformBus::Events::SetParent, containerEntityId); + } } // Update the template of the instance since the entities are modified since the template creation.