From e1829ac05238797da5245a3b9392003e5812ea62 Mon Sep 17 00:00:00 2001 From: AMZN-AlexOteiza Date: Fri, 10 Sep 2021 11:19:58 +0200 Subject: [PATCH] Added EntityExists for automation Signed-off-by: AMZN-AlexOteiza --- .../AzToolsFramework/API/ToolsApplicationAPI.h | 3 +++ .../Application/ToolsApplication.cpp | 14 ++++++++++---- .../Application/ToolsApplication.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h index d4707a3e8c..c037747a08 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h @@ -414,6 +414,9 @@ namespace AzToolsFramework //! Gets an existing entity id from a known id. virtual AZ::EntityId GetExistingEntity(AZ::u64 id) = 0; + //! Returns if an entity with the given id exists + virtual bool EntityExists(AZ::EntityId id) = 0; + /*! * Delete all currently-selected entities. */ diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.cpp index 6de529e456..0a6022eeba 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.cpp @@ -378,6 +378,7 @@ namespace AzToolsFramework ->Event("CreateNewEntityAtPosition", &ToolsApplicationRequests::CreateNewEntityAtPosition) ->Event("GetCurrentLevelEntityId", &ToolsApplicationRequests::GetCurrentLevelEntityId) ->Event("GetExistingEntity", &ToolsApplicationRequests::GetExistingEntity) + ->Event("EntityExists", &ToolsApplicationRequests::EntityExists) ->Event("DeleteEntityById", &ToolsApplicationRequests::DeleteEntityById) ->Event("DeleteEntities", &ToolsApplicationRequests::DeleteEntities) ->Event("DeleteEntityAndAllDescendants", &ToolsApplicationRequests::DeleteEntityAndAllDescendants) @@ -483,7 +484,7 @@ namespace AzToolsFramework EBUS_EVENT_RESULT(serializeContext, AZ::ComponentApplicationBus, GetSerializeContext); AZ_Assert(serializeContext, "No serialization context found"); - const AZ::Entity::ComponentArrayType& editorComponents = source.GetComponents(); + const AZ::Entity::ComponentArrayType& editorComponents = source.GetUserComponents(); // Propagate components from source entity to target, in preparation for exporting target. for (AZ::Component* component : editorComponents) @@ -493,15 +494,15 @@ namespace AzToolsFramework if (asEditorComponent) { - const size_t oldComponentCount = target.GetComponents().size(); + const size_t oldComponentCount = target.GetUserComponents().size(); asEditorComponent->BuildGameEntity(&target); // Applying same Id persistence trick as we do in the slice compiler. Once we're off levels, // this code all goes away and everything runs through the slice compiler. - if (target.GetComponents().size() > oldComponentCount) + if (target.GetUserComponents().size() > oldComponentCount) { - AZ::Component* newComponent = target.GetComponents().back(); + AZ::Component* newComponent = target.GetUserComponents().back(); AZ_Error("Export", asEditorComponent->GetId() != AZ::InvalidComponentId, "For entity \"%s\", component \"%s\" doesn't have a valid component id", source.GetName().c_str(), asEditorComponent->RTTI_GetType().ToString().c_str()); newComponent->SetId(asEditorComponent->GetId()); @@ -783,6 +784,11 @@ namespace AzToolsFramework return AZ::EntityId{id}; } + bool ToolsApplication::EntityExists(AZ::EntityId id) + { + return FindEntity(id) != nullptr; + } + void ToolsApplication::DeleteSelected() { if (IsPrefabSystemEnabled()) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.h index e7fa543faf..d05ec5728d 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.h @@ -115,6 +115,7 @@ namespace AzToolsFramework AZ::EntityId CreateNewEntity(AZ::EntityId parentId = AZ::EntityId()) override; AZ::EntityId CreateNewEntityAtPosition(const AZ::Vector3& pos, AZ::EntityId parentId = AZ::EntityId()) override; AZ::EntityId GetExistingEntity(AZ::u64 id) override; + bool EntityExists(AZ::EntityId id) override; void DeleteSelected() override; void DeleteEntityById(AZ::EntityId entityId) override; void DeleteEntities(const EntityIdList& entities) override;