SliceConverterEditorEntityContextComponent.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzToolsFramework/Entity/EditorEntityContextComponent.h>
  10. namespace AzToolsFramework
  11. {
  12. // This class is an inelegant workaround for use by the Slice Converter to selectively disable entity add/remove logic
  13. // during slice conversion in the EditorEntityContextComponent. Specifically, the standard versions of these methods will
  14. // attempt to activate the entities as they're added. This is both unnecessary and undesirable during slice conversion, since
  15. // entity activation requires a lot of subsystems to be active and valid.
  16. // Instead, by selectively disabling this logic, the entities can remain in an initialized state, which is sufficient for conversion,
  17. // without requiring those extra subsystems.
  18. // This problem also could have been solved by adding APIs to the EditorEntityContextComponent or the EntityContext, but there aren't
  19. // any other known valid use cases for disabling this logic, so the extra APIs would simply encourage "bad behavior" by using them
  20. // when they likely aren't necessary or desired.
  21. class SliceConverterEditorEntityContextComponent
  22. : public EditorEntityContextComponent
  23. {
  24. public:
  25. AZ_COMPONENT(SliceConverterEditorEntityContextComponent, "{1CB0C38F-8E85-4422-91C6-E1F3B9B4B853}");
  26. SliceConverterEditorEntityContextComponent() : EditorEntityContextComponent() {}
  27. // Simple API to selectively disable this logic *only* when performing slice to prefab conversion.
  28. static inline void DisableOnContextEntityLogic()
  29. {
  30. m_enableOnContextEntityLogic = false;
  31. }
  32. protected:
  33. void OnContextEntitiesAdded([[maybe_unused]] const EntityList& entities) override
  34. {
  35. if (m_enableOnContextEntityLogic)
  36. {
  37. EditorEntityContextComponent::OnContextEntitiesAdded(entities);
  38. }
  39. }
  40. void OnContextEntityRemoved([[maybe_unused]] const AZ::EntityId& id) override
  41. {
  42. if (m_enableOnContextEntityLogic)
  43. {
  44. EditorEntityContextComponent::OnContextEntityRemoved(id);
  45. }
  46. }
  47. // By default, act just like the EditorEntityContextComponent
  48. static inline bool m_enableOnContextEntityLogic = true;
  49. };
  50. } // namespace AzToolsFramework