Open 3D Engine AzCore API Reference  2305.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
Component.h File Reference
#include <AzCore/Component/ComponentBus.h>
#include <AzCore/Component/NamedEntityId.h>
#include <AzCore/RTTI/ReflectContext.h>
#include <AzCore/Memory/Memory.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Outcome/Outcome.h>
#include <AzCore/std/containers/unordered_set.h>

Classes

class  AZ::Component
 
class  AZ::ComponentDescriptor
 
struct  AZ::ComponentDescriptorBusTraits
 
class  AZ::ComponentDescriptorHelper< ComponentClass >
 
class  AZ::ComponentDescriptorDefault< ComponentClass >
 

Namespaces

 AZ
 Reopen namespace to define DataPatch class.
 

Macros

#define AZ_COMPONENT_BASE(_ComponentClass,...)
 
#define AZ_COMPONENT_INTRUSIVE_DESCRIPTOR_TYPE(_ComponentClass)
 
#define AZ_COMPONENT(_ComponentClass,...)
 

Typedefs

typedef AZ::u32 AZ::ComponentServiceType
 ID of a user-defined component service. The system uses it to build a dependency tree.
 
using AZ::ImmutableEntityVector = AZStd::vector< AZ::Entity const * >
 
using AZ::ComponentTypeList = AZStd::vector< Uuid >
 List of Component class type IDs.
 
using AZ::ComponentValidationResult = AZ::Outcome< void, AZStd::string >
 
using AZ::ComponentDescriptorBus = AZ::EBus< ComponentDescriptor, ComponentDescriptorBusTraits >
 

Functions

 DECLARE_EBUS_EXTERN_WITH_TRAITS (ComponentDescriptor, ComponentDescriptorBusTraits)
 

Detailed Description

Header file for the Component base class. In Open 3D Engine's component entity system, each component defines a discrete feature that can be attached to an entity.

Macro Definition Documentation

#define AZ_COMPONENT (   _ComponentClass,
  ... 
)
Value:
AZ_RTTI(_ComponentClass, __VA_ARGS__, AZ::Component) \
AZ_COMPONENT_BASE(_ComponentClass, __VA_ARGS__)
#define AZ_COMPONENT_INTRUSIVE_DESCRIPTOR_TYPE(_ComponentClass)
Definition: Component.h:295
#define AZ_COMPONENT_BASE(_ComponentClass,...)
Definition: Component.h:259
Definition: Component.h:41

Declares a component with the default settings. The component derives from AZ::Component, is not templated, uses AZ::SystemAllocator, and so on. AZ_COMPONENT(_ComponentClass, _ComponentId, OtherBaseClases... Component) is included automatically.

The component that this macro creates has a static function called CreateDescriptor and a type called DescriptorType. Although you can delete the descriptor, keep in mind that you cannot use component instances without a descriptor. This is because descriptors are released when the component application closes or a module is unloaded. Descriptors must have access to AZ::ComponentDescriptor::Reflect, AZ::ComponentDescriptor::GetProvidedServices, and other descriptor services.

You are not required to use the AZ_COMPONENT macro if you want to implement your own creation functions by calling AZ_CLASS_ALLOCATOR, AZ_RTTI, and so on.

#define AZ_COMPONENT_BASE (   _ComponentClass,
  ... 
)
Value:
AZ_CLASS_ALLOCATOR(_ComponentClass, AZ::SystemAllocator) \
template<class Comp, class Void> friend class AZ::HasComponentReflect; \
template<class Comp, class Void> friend class AZ::HasComponentProvidedServices; \
template<class Comp, class Void> friend class AZ::HasComponentDependentServices; \
template<class Comp, class Void> friend class AZ::HasComponentRequiredServices; \
template<class Comp, class Void> friend class AZ::HasComponentIncompatibleServices; \
static AZ::ComponentDescriptor* CreateDescriptor() \
{ \
static const char* s_typeName = _ComponentClass::RTTI_TypeName(); \
static const AZ::TypeId s_typeId = _ComponentClass::RTTI_Type(); \
AZ::ComponentDescriptor* descriptor = nullptr; \
AZ::ComponentDescriptorBus::EventResult(descriptor, s_typeId, &AZ::ComponentDescriptor::GetDescriptor); \
if (descriptor) \
{ \
/* Compare strings first, then pointers. */ \
if (descriptor->GetName() != AZStd::string_view(s_typeName)) \
{ \
AZ_Error("Component", false, "Two different components have the same UUID (%s), which is not allowed.\n" \
"Change the UUID on one of them.\nComponent A: %s\nComponent B: %s", \
s_typeId.ToFixedString().c_str(), descriptor->GetName(), s_typeName); \
return nullptr; \
} \
return descriptor; \
} \
return aznew DescriptorType; \
}
virtual ComponentDescriptor * GetDescriptor()
Definition: Component.h:415
Definition: SystemAllocator.h:26
Definition: Component.h:326
Definition: Uuid.h:24
Definition: IConsoleTypes.h:21

Includes the core component code required to make a component work. This macro is typically included in other macros, such as AZ_COMPONENT, to create a component.

#define AZ_COMPONENT_INTRUSIVE_DESCRIPTOR_TYPE (   _ComponentClass)
Value:
friend class AZ::ComponentDescriptorDefault<_ComponentClass>; \
Definition: Component.h:512

Declares a descriptor class. Unless you are implementing very advanced internal functionality, we recommend using AZ_COMPONENT instead of this macro. This macro enables you to implement a static function in the Component class instead of writing a descriptor. It defines a CreateDescriptorFunction that you can call to register a descriptor. (Only one descriptor can exist per environment.) This macro fails silently if you implement the functions with the wrong signatures.