diff --git a/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextBus.h b/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextBus.h index ca2b9413b4..85eeb2c4c0 100644 --- a/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextBus.h +++ b/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextBus.h @@ -90,6 +90,15 @@ namespace AzFramework */ virtual void DestroyGameEntity(const AZ::EntityId& /*id*/) = 0; + /** + * Destroys an entity only in slice mode (when prefabs are disabled). This request is only added as a stop-gap solution to + * prevent the editor from crashing when prefabs are enabled. This will be removed soon. Please use 'DestroyGameEntity' if your + * intention is to destroy a game entity in slice mode. + * + * \param id The ID of the entity to destroy. + */ + virtual void DestroyGameEntityOnlyInSliceMode(const AZ::EntityId& /*id*/) = 0; + /** * Destroys an entity and all of its descendants. * The entity and its descendants are immediately deactivated and will be @@ -98,6 +107,15 @@ namespace AzFramework */ virtual void DestroyGameEntityAndDescendants(const AZ::EntityId& /*id*/) = 0; + /** + * Destroys an entity and its descendants only in slice mode (when prefabs are disabled). This request is only added as a stop-gap + * solution to prevent the editor from crashing when prefabs are enabled. This will be removed soon. Please use + * 'DestroyGameEntityAndDescendants' if your intention is to destroy a game entity and its descendants in slice mode. + * + * \param id The ID of the entity to destroy. + */ + virtual void DestroyGameEntityAndDescendantsOnlyInSliceMode(const AZ::EntityId& /*id*/) = 0; + /** * Activates the game entity. * @param id The ID of the entity to activate. diff --git a/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextComponent.cpp b/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextComponent.cpp index e48c9a43e1..0c4199b267 100644 --- a/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextComponent.cpp +++ b/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextComponent.cpp @@ -46,8 +46,9 @@ namespace AzFramework ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) ->Event("CreateGameEntity", &GameEntityContextRequestBus::Events::CreateGameEntityForBehaviorContext) ->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All) - ->Event("DestroyGameEntity", &GameEntityContextRequestBus::Events::DestroyGameEntity) - ->Event("DestroyGameEntityAndDescendants", &GameEntityContextRequestBus::Events::DestroyGameEntityAndDescendants) + ->Event("DestroyGameEntity", &GameEntityContextRequestBus::Events::DestroyGameEntityOnlyInSliceMode) + ->Event( + "DestroyGameEntityAndDescendants", &GameEntityContextRequestBus::Events::DestroyGameEntityAndDescendantsOnlyInSliceMode) ->Event("ActivateGameEntity", &GameEntityContextRequestBus::Events::ActivateGameEntity) ->Event("DeactivateGameEntity", &GameEntityContextRequestBus::Events::DeactivateGameEntity) ->Attribute(AZ::ScriptCanvasAttributes::DeactivatesInputEntity, true) @@ -247,6 +248,23 @@ namespace AzFramework DestroyGameEntityInternal(id, false); } + void GameEntityContextComponent::DestroyGameEntityOnlyInSliceMode(const AZ::EntityId& id) + { + bool isPrefabSystemEnabled = false; + AzFramework::ApplicationRequests::Bus::BroadcastResult( + isPrefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); + if (!isPrefabSystemEnabled) + { + DestroyGameEntityInternal(id, false); + } + else + { + AZ_Error( + "GameEntityContextComponent", false, + "Destroying a game entity is temporarily disabled until the Spawnable system can support this."); + } + } + //========================================================================= // GameEntityContextComponent::DestroyGameEntityAndDescendantsById //========================================================================= @@ -255,6 +273,24 @@ namespace AzFramework DestroyGameEntityInternal(id, true); } + + void GameEntityContextComponent::DestroyGameEntityAndDescendantsOnlyInSliceMode(const AZ::EntityId& id) + { + bool isPrefabSystemEnabled = false; + AzFramework::ApplicationRequests::Bus::BroadcastResult( + isPrefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); + if (!isPrefabSystemEnabled) + { + DestroyGameEntityInternal(id, true); + } + else + { + AZ_Error( + "GameEntityContextComponent", false, + "Destroying a game entity and its descendants is temporarily disabled until the Spawnable system can support this."); + } + } + //========================================================================= // GameEntityContextComponent::DestroyGameEntityInternal //========================================================================= diff --git a/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextComponent.h b/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextComponent.h index 6e6d1c64c9..65a8ce53b4 100644 --- a/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextComponent.h +++ b/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextComponent.h @@ -89,6 +89,12 @@ namespace AzFramework } private: + ////////////////////////////////////////////////////////////////////////// + // GameEntityContextRequestBus + void DestroyGameEntityOnlyInSliceMode(const AZ::EntityId&) override; + void DestroyGameEntityAndDescendantsOnlyInSliceMode(const AZ::EntityId&) override; + ///////////////////////////////////////////////////////////////////////// + AzFramework::EntityVisibilityBoundsUnionSystem m_entityVisibilityBoundsUnionSystem; }; } // namespace AzFramework