Open 3D Engine AzCore API Reference  24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Component Class Referenceabstract

#include <Component.h>

Inherited by AZ::AssetManagerComponent, AZ::AzStdReflectionComponent, AZ::EventSchedulerSystemComponent, AZ::JobManagerComponent, AZ::JsonSystemComponent, AZ::LoggerSystemComponent, AZ::ScriptSystemComponent, AZ::SliceComponent, AZ::SliceMetadataInfoComponent, AZ::SliceSystemComponent, AZ::Statistics::StatisticalProfilerProxySystemComponent, AZ::StreamerComponent, AZ::TaskGraphSystemComponent, and AZ::UserSettingsComponent.

Public Member Functions

 AZ_TYPE_INFO_WITH_NAME_DECL (Component)
 
 AZ_RTTI_NO_TYPE_INFO_DECL ()
 
AZ_CLASS_ALLOCATOR_DECL Component ()
 
virtual ~Component ()
 
EntityGetEntity () const
 
EntityId GetEntityId () const
 
NamedEntityId GetNamedEntityId () const
 
ComponentId GetId () const
 
virtual TypeId GetUnderlyingComponentType () const
 
void SetId (const ComponentId &id)
 
virtual void SetSerializedIdentifier (AZStd::string serializedIdentifer)
 
virtual AZStd::string GetSerializedIdentifier () const
 
virtual ComponentValidationResult ValidateComponentRequirements (const ImmutableEntityVector &, const AZStd::unordered_set< AZ::Crc32 > &) const
 
bool SetConfiguration (const AZ::ComponentConfig &config)
 
bool GetConfiguration (AZ::ComponentConfig &outConfig) const
 

Protected Member Functions

virtual void Init ()
 
virtual void Activate ()=0
 
virtual void Deactivate ()=0
 
virtual bool ReadInConfig (const ComponentConfig *baseConfig)
 
virtual bool WriteOutConfig (ComponentConfig *outBaseConfig) const
 
virtual void SetEntity (Entity *entity)
 
virtual void OnAfterEntitySet ()
 Function to call after setting the entity in this component.
 

Protected Attributes

Entitym_entity
 Reference to the entity that owns the component. The value is null if the component is not attached to an entity.
 
ComponentId m_id
 A component ID that is unique for an entity. This component ID is not unique across all entities.
 

Friends

class Entity
 

Detailed Description

Base class for all components.

Constructor & Destructor Documentation

◆ Component()

AZ_CLASS_ALLOCATOR_DECL AZ::Component::Component ( )

Initializes a component's internals. A component's constructor should initialize the component's variables only. Because the component is not active yet, it should not connect to message buses, send messages, and so on. Similarly, the component's constructor should not attempt to cache pointers or data from other components on the same entity because those components can be added or removed at any moment. To process and initialize all resources that make a component ready to operate, use Init().

◆ ~Component()

virtual AZ::Component::~Component ( )
virtual

Destroys a component. The system always calls a component's Deactivate() function before destroying it.

Member Function Documentation

◆ Activate()

virtual void AZ::Component::Activate ( )
protectedpure virtual

Puts the component into an active state. The system calls this function once during activation of each entity that owns the component. You must override this function. The system calls a component's Activate() function only if all services and components that the component depends on are present and active. Use GetProvidedServices and GetDependentServices to specify these dependencies.

Implemented in AZ::UserSettingsComponent, AZ::Statistics::StatisticalProfilerProxySystemComponent, AZ::SliceSystemComponent, AZ::SliceMetadataInfoComponent, AZ::SliceComponent, AZ::JsonSystemComponent, AZ::ScriptSystemComponent, AZ::AzStdReflectionComponent, AZ::EventSchedulerSystemComponent, AZ::LoggerSystemComponent, and AZ::AssetManagerComponent.

◆ AZ_TYPE_INFO_WITH_NAME_DECL()

AZ::Component::AZ_TYPE_INFO_WITH_NAME_DECL ( Component  )

Forward declare run-time type information to the component.

◆ Deactivate()

virtual void AZ::Component::Deactivate ( )
protectedpure virtual

Deactivates the component. The system calls this function when the owning entity is being deactivated. You must override this function. As a best practice, ensure that this function returns the component to a minimal footprint. The order of deactivation is the reverse of activation, so your component is deactivated before the components it depends on.

The system always calls the component's Deactivate() function before destroying the component. However, deactivation is not always followed by the destruction of the component. An entity and its components can be deactivated and reactivated without being destroyed. Ensure that your Deactivate() implementation can handle this scenario.

Implemented in AZ::UserSettingsComponent, AZ::Statistics::StatisticalProfilerProxySystemComponent, AZ::SliceSystemComponent, AZ::SliceMetadataInfoComponent, AZ::SliceComponent, AZ::JsonSystemComponent, AZ::ScriptSystemComponent, AZ::AzStdReflectionComponent, AZ::EventSchedulerSystemComponent, AZ::LoggerSystemComponent, and AZ::AssetManagerComponent.

◆ GetConfiguration()

bool AZ::Component::GetConfiguration ( AZ::ComponentConfig outConfig) const

Get a component's configuration. A component must implement the WriteOutConfig() function for this to have an effect.

Parameters
outConfig[out]The component will copy its properties into this configuration class. The configuration class must be of the appropriate type for this component. For example, use a TransformConfig with a TransformComponent.

◆ GetEntity()

Entity* AZ::Component::GetEntity ( ) const
inline

Returns a pointer to the entity. If the component is not attached to any entity, this function returns a null pointer. In that case, the component is in the default state (not activated). However, except in the case of tools, you typically should not use this function. It is a best practice to access other components through EBuses instead of accessing them directly. For more information, see the O3DE Component Development documentation.

Returns
A pointer to the entity. If the component is not attached to any entity, the return value is a null pointer.

◆ GetEntityId()

EntityId AZ::Component::GetEntityId ( ) const

Returns the entity ID if the component is attached to an entity. If the component is not attached to any entity, this function asserts. As a safeguard, make sure that GetEntity()!=nullptr.

Returns
The ID of the entity that contains the component.

◆ GetId()

ComponentId AZ::Component::GetId ( ) const
inline

Returns the component ID, which is valid only when the component is attached to an entity. If the component is not attached to any entity, the return value is 0. As a safeguard, make sure that GetEntity()!=nullptr.

Returns
The ID of the component. If the component is attached to any entity, the return value is 0.

◆ GetNamedEntityId()

NamedEntityId AZ::Component::GetNamedEntityId ( ) const

Returns the NamedEntityId if the component is attached to an entity. If the component is not attached to any entity, this function asserts. As a safeguard, make sure that GetEntity()!=nullptr.

Returns
The ID of the entity that contains the component.

◆ GetSerializedIdentifier()

virtual AZStd::string AZ::Component::GetSerializedIdentifier ( ) const
virtual

Gets the serialzied identifier of this component within an entity. This will be a non-empty string for components that inherit from EditorComponentBase. For all others, it'll be empty.

Returns
The serialized identifier of this component.

◆ GetUnderlyingComponentType()

virtual TypeId AZ::Component::GetUnderlyingComponentType ( ) const
inlinevirtual

Returns the type ID Can be overridden for components that wrap other components, to provide a punch through to the wrapped component's ID.

Returns
The type ID of the component.

◆ Init()

virtual void AZ::Component::Init ( )
inlineprotectedvirtual

Initializes a component's resources. (Optional) Override this function to initialize resources that the component needs. The system calls this function once for each entity that owns the component. Although the Init() function initializes the component, the component is not active until the system calls the component's Activate() function. We recommend that you minimize the component's CPU and memory overhead when the component is inactive.

◆ ReadInConfig()

virtual bool AZ::Component::ReadInConfig ( const ComponentConfig baseConfig)
protectedvirtual

Read properties from the configuration class into the component. Overriding this function allows your component to be configured at runtime. See AZ::ComponentConfig for more details. This function cannot be invoked while the component is activated.

// sample implementation
bool ReadInConfig(const ComponentConfig* baseConfig) override
{
if (auto config = azrtti_cast<const MyConfig*>(baseConfig))
{
m_propertyA = config->m_propertyA;
m_propertyB = config->m_propertyB
return true;
}
return false;
}
virtual bool ReadInConfig(const ComponentConfig *baseConfig)

◆ SetConfiguration()

bool AZ::Component::SetConfiguration ( const AZ::ComponentConfig config)

Set the component's configuration. A component cannot be configured while it is activated. A component must implement the ReadInConfig() function for this to have an effect.

Parameters
configThe component will set its properties based on this configuration. The configuration class must be of the appropriate type for this component. For example, use a TransformConfig with a TransformComponent.

◆ SetEntity()

virtual void AZ::Component::SetEntity ( Entity entity)
protectedvirtual

Sets the current entity. This function is called by the entity.

Parameters
entityThe current entity.

◆ SetId()

void AZ::Component::SetId ( const ComponentId &  id)
inline

Sets the component ID. This function is for internal use only.

Parameters
idThe ID to assign to the component.

◆ SetSerializedIdentifier()

virtual void AZ::Component::SetSerializedIdentifier ( AZStd::string  serializedIdentifer)
virtual

Sets the provided string as the serialized identifier for the component. This should be done only for editor components since those are the only ones that'll be written to disk.

Parameters
serializedIdentiferThe unique identifier for this component within the entity it lives in.

◆ ValidateComponentRequirements()

virtual ComponentValidationResult AZ::Component::ValidateComponentRequirements ( const ImmutableEntityVector ,
const AZStd::unordered_set< AZ::Crc32 > &   
) const
inlinevirtual

Override to conduct per-component or per-slice validation logic during slice asset processing.

Parameters
sliceEntitiesAll entities that belong to the slice that the entity with this component is on.
platformTagsList of platforms supplied during slice asset processing.

◆ WriteOutConfig()

virtual bool AZ::Component::WriteOutConfig ( ComponentConfig outBaseConfig) const
protectedvirtual

Write properties from the component into the configuration class. Overriding this function allows your component's configuration to be queried at runtime. See AZ::ComponentConfig for more details.

// sample implementation
bool WriteOutConfig(ComponentConfig* outBaseConfig) const override
{
if (auto config = azrtti_cast<MyConfig*>(outBaseConfig))
{
config->m_propertyA = m_propertyA;
config->m_propertyB = m_propertyB;
return true;
}
return false;
}
virtual bool WriteOutConfig(ComponentConfig *outBaseConfig) const

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