From e22398700dc45d2f5be50c8e23f6d4fb89323698 Mon Sep 17 00:00:00 2001 From: daimini Date: Thu, 29 Apr 2021 16:19:58 -0700 Subject: [PATCH] Simplified some checks, added early outs. --- .../Prefab/PrefabPublicHandler.cpp | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 46c3eaefe4..da4eee2263 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -143,7 +143,7 @@ namespace AzToolsFramework for (AZ::Entity* topLevelEntity : topLevelEntities) { AZ::EntityId topLevelEntityId = topLevelEntity->GetId(); - if (topLevelEntityId.IsValid() && !IsLevelInstanceContainerEntity(topLevelEntityId)) + if (topLevelEntityId.IsValid()) { m_prefabUndoCache.UpdateCache(topLevelEntityId); undoBatch.MarkEntityDirty(topLevelEntityId); @@ -228,11 +228,18 @@ namespace AzToolsFramework inputEntityList = EntityIdListToEntityList(entityIds); // Remove Level Container Entity if it's part of the list - AZ::Entity* levelEntity = GetEntityById(GetLevelInstanceContainerEntityId()); - auto levelEntityIter = AZStd::find(inputEntityList.begin(), inputEntityList.end(), levelEntity); - if (levelEntityIter != inputEntityList.end()) + AZ::EntityId levelEntityId = GetLevelInstanceContainerEntityId(); + if (levelEntityId.IsValid()) { - inputEntityList.erase(levelEntityIter); + AZ::Entity* levelEntity = GetEntityById(levelEntityId); + if (levelEntity) + { + auto levelEntityIter = AZStd::find(inputEntityList.begin(), inputEntityList.end(), levelEntity); + if (levelEntityIter != inputEntityList.end()) + { + inputEntityList.erase(levelEntityIter); + } + } } // Find common root and top level entities @@ -765,6 +772,11 @@ namespace AzToolsFramework const EntityList& inputEntities, Instance& commonRootEntityOwningInstance, EntityList& outEntities, AZStd::vector>& outInstances) const { + if (inputEntities.size() == 0) + { + return false; + } + AZStd::queue entityQueue; for (auto inputEntity : inputEntities)