Open 3D Engine AzToolsFramework API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AzToolsFramework::Components::EditorComponentAdapter< TController, TRuntimeComponent, TConfiguration > Class Template Reference

#include <EditorComponentAdapter.h>

Inherits AzToolsFramework::Components::EditorComponentBase.

Public Member Functions

 AZ_RTTI ((EditorComponentAdapter, "{2F5A3669-FFE9-4CD7-B9E2-7FC8100CF1A2}", TController, TRuntimeComponent, TConfiguration), EditorComponentBase)
 
 EditorComponentAdapter (const TConfiguration &configuration)
 
void Init () override
 
void Activate () override
 
void Deactivate () override
 
void BuildGameEntity (AZ::Entity *gameEntity) override
 
- Public Member Functions inherited from AzToolsFramework::Components::EditorComponentBase
 AZ_RTTI (EditorComponentBase, "{D5346BD4-7F20-444E-B370-327ACD03D4A0}", AZ::Component)
 
 EditorComponentBase ()
 
void SetDirty ()
 
virtual void Init () override
 
virtual void Activate () override
 
virtual void Deactivate () override
 
void OnAfterEntitySet () override final
 
void SetSerializedIdentifier (AZStd::string serializedIdentifier) override final
 
AZStd::string GetSerializedIdentifier () const override final
 
AZ::TransformInterface * GetTransform () const
 
AZ::Transform GetWorldTM () const
 
AZ::Transform GetLocalTM () const
 
bool IsSelected () const
 
virtual void BuildGameEntity (AZ::Entity *)
 
virtual void SetPrimaryAsset (const AZ::Data::AssetId &)
 
virtual void AddContextMenuActions (QMenu *)
 

Static Public Member Functions

static void GetProvidedServices (AZ::ComponentDescriptor::DependencyArrayType &services)
 
static void GetIncompatibleServices (AZ::ComponentDescriptor::DependencyArrayType &services)
 
static void GetRequiredServices (AZ::ComponentDescriptor::DependencyArrayType &services)
 
static void GetDependentServices (AZ::ComponentDescriptor::DependencyArrayType &services)
 
- Static Public Member Functions inherited from AzToolsFramework::Components::EditorComponentBase
static void Reflect (AZ::ReflectContext *context)
 

Protected Member Functions

bool ReadInConfig (const AZ::ComponentConfig *baseConfig) override
 
bool WriteOutConfig (AZ::ComponentConfig *outBaseConfig) const override
 
virtual AZ::u32 OnConfigurationChanged ()
 
virtual bool ShouldActivateController () const
 

Static Protected Member Functions

static void Reflect (AZ::ReflectContext *context)
 

Protected Attributes

TController m_controller
 

Detailed Description

template<typename TController, typename TRuntimeComponent, typename TConfiguration = AZ::ComponentConfig>
class AzToolsFramework::Components::EditorComponentAdapter< TController, TRuntimeComponent, TConfiguration >

EditorComponentAdapter is a utility base class that provides a consistent pattern for implementing components that operate in the editor but may need to share code in different contexts like the launcher.

EditorComponentAdapter achieves this by delegating to a controller class that implements common behavior instead of duplicating code between multiple components.

To use the EditorComponentAdapter, 3 classes are required:

  • a class that implements the functions required for TController (see below)
  • a configuration struct/class which extends AZ::ComponentConfig
  • A runtime component that will be generated by the editor component on export

The concrete component extends the adapter and implements behavior which is unique to the component.

TController can handle any common functionality between the runtime and editor component and is where most of the code for the component will live

TConfiguration is where any data that needs to be serialized out should live.

TController must implement certain functions to conform to the template. These functions mirror those in AZ::Component and must be accesible to any adapter that follows this pattern:

static void Reflect(AZ::ReflectContext* context);
void Activate(EntityId entityId);
void Deactivate();
void SetConfiguration(const ComponentConfigurationType& config);
const ComponentConfigurationType& GetConfiguration() const;
void Activate() override
Definition: EditorComponentAdapter.inl:100
void Deactivate() override
Definition: EditorComponentAdapter.inl:112

In addition, certain functions will optionally be called if they are available:

static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
void Init();
void Init() override
Definition: EditorComponentAdapter.inl:93

It is recommended that TController handle the SerializeContext, but the editor components handle the EditContext. TController can friend itself to the editor component to make this work if required.

Member Function Documentation

◆ Activate()

template<typename TController , typename TRuntimeComponent , typename TConfiguration >
void AzToolsFramework::Components::EditorComponentAdapter< TController, TRuntimeComponent, TConfiguration >::Activate ( )
overridevirtual

Gets the transform component and selection component of the entity that the component belongs to, if the entity has them. Overrides AZ::Component::Activate().

Important: Components derived from EditorComponentBase must call the Activate() function of the base class.

Reimplemented from AzToolsFramework::Components::EditorComponentBase.

◆ BuildGameEntity()

template<typename TController , typename TRuntimeComponent , typename TConfiguration >
void AzToolsFramework::Components::EditorComponentAdapter< TController, TRuntimeComponent, TConfiguration >::BuildGameEntity ( AZ::Entity *  )
overridevirtual

Override this function to create one or more game components to represent your editor component in runtime.

Important: If your entity has a game component, you must implement this function.

This function is called by the slice builder. Any game components that you create should be attached to the game entity that is provided to this function. If you do not need to create a game component, you do not need to override this function. The provided component to the gameEntity is dynamically generated and owned by the gameEntity and should be deallocated appropriately.

Parameters
gameEntityA pointer to the game entity.

Reimplemented from AzToolsFramework::Components::EditorComponentBase.

◆ Deactivate()

template<typename TController , typename TRuntimeComponent , typename TConfiguration >
void AzToolsFramework::Components::EditorComponentAdapter< TController, TRuntimeComponent, TConfiguration >::Deactivate ( )
overridevirtual

Sets the component's pointers to the transform component and selection component to null. Overrides AZ::Component::Deactivate().

Important: Components derived from EditorComponentBase must call the Deactivate() function of the base class.

Reimplemented from AzToolsFramework::Components::EditorComponentBase.

◆ Init()

template<typename TController , typename TRuntimeComponent , typename TConfiguration >
void AzToolsFramework::Components::EditorComponentAdapter< TController, TRuntimeComponent, TConfiguration >::Init ( )
overridevirtual

Initializes the component's resources. Overrides AZ::Component::Init().

Important: Components derived from EditorComponentBase must call the Init() function of the base class.

(Optional) You can override this function to initialize resources that the component needs.

Reimplemented from AzToolsFramework::Components::EditorComponentBase.


The documentation for this class was generated from the following files: