diff --git a/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextBus.h b/Code/Framework/AzFramework/AzFramework/Entity/GameEntityContextBus.h index 726ed39916..6ddeda3cbf 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 and must only be called through the BehaviorContext binding + * for 'DestroyGameEntity'. No code should be written to directly call this method. This will be removed soon. + * + * @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 and must only be called through the BehaviorContext + * binding for 'DestroyGameEntityAndDescendants'.No code should be written to directly call this method. This will be removed soon. + * + * @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 4f4b67cf27..4c50722843 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 86672c3d47..3fa4d2b35c 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