ezEngine  Milestone 7
ezComponent Class Referenceabstract

Base class of all component types. More...

#include <Component.h>

Inheritance diagram for ezComponent:

Public Member Functions

bool IsDynamic () const
 Returns whether this component is dynamic and thus can only be attached to dynamic game objects.
 
void SetActive (bool bActive)
 Sets the active state of the component. Note that it is up to the manager if he differentiates between active and inactive components.
 
void Activate ()
 Activates the component. Note that it is up to the manager if he differentiates between active and inactive components.
 
void Deactivate ()
 Deactivates the component.
 
bool IsActive () const
 Returns whether this component is active.
 
ezComponentManagerBaseGetManager () const
 Returns the corresponding manager for this component.
 
ezGameObjectGetOwner ()
 Returns the owner game object if the component is attached to one or nullptr.
 
const ezGameObjectGetOwner () const
 Returns the owner game object if the component is attached to one or nullptr.
 
ezComponentHandle GetHandle () const
 Returns a handle to this component.
 
- Public Member Functions inherited from ezReflectedClass
EZ_FORCE_INLINE bool IsInstanceOf (const ezRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T >
EZ_FORCE_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 
virtual void Serialize (ezArchiveWriter &stream) const
 This function is called to serialize the instance. More...
 
virtual void Deserialize (ezArchiveReader &stream)
 This function is called to deserialize the instance. More...
 
virtual void OnDeserialized ()
 This function is called after all objects are deserialized and thus all references to other objects are valid. More...
 

Static Public Member Functions

static ezUInt16 TypeId ()
 Returns the type id corresponding to this component type.
 
static ezUInt16 GetNextTypeId ()
 Gets the next component id for a new type. Internal use only.
 

Public Attributes

ezUInt32 m_uiEditorPickingID
 

Protected Member Functions

 ezComponent ()
 Keep the constructor private or protected in derived classes, so it cannot be called manually.
 
template<typename T >
ezComponentHandle GetHandle () const
 

Protected Attributes

ezBitflags< ezObjectFlagsm_Flags
 

Private Member Functions

 EZ_ADD_DYNAMIC_REFLECTION (ezComponent)
 
virtual ezUInt16 GetTypeId () const =0
 
virtual ezResult Initialize ()
 This method is called after the constructor. A derived type can override this method to do common initialization work.
 
virtual ezResult Deinitialize ()
 This method is called before the destructor. A derived type can override this method to do common deinitialization work.
 
bool IsInitialized () const
 Returns whether this component is initialized. Internal method.
 
virtual void OnAfterAttachedToObject ()
 This method is called when the component is attached to a game object. At this point the owner pointer is already set. A derived type can override this method to do additional work.
 
virtual void OnBeforeDetachedFromObject ()
 This method is called when the component is detached from a game object. At this point the owner pointer is still set. A derived type can override this method to do additional work.
 
void OnMessage (ezMessage &msg)
 
void OnMessage (ezMessage &msg) const
 

Private Attributes

ezGenericComponentId m_InternalId
 
ezComponentManagerBasem_pManager
 
ezGameObjectm_pOwner
 

Static Private Attributes

static ezUInt16 TYPE_ID = ezComponent::GetNextTypeId()
 
static ezUInt16 s_uiNextTypeId
 

Friends

class ezWorld
 
class ezGameObject
 
class ezComponentManagerBase
 

Detailed Description

Base class of all component types.

Derive from this class to implement custom component types. Also add the EZ_DECLARE_COMPONENT_TYPE macro to your class declaration. Also add a EZ_BEGIN_COMPONENT_TYPE/EZ_END_COMPONENT_TYPE block to a cpp file. In that block you can add reflected members or message handlers. Note that every component type needs a corresponding manager type. Take a look at ezComponentManagerSimple for a simple manager implementation that calls an update method on its components every frame. To create a component instance call CreateComponent on the corresponding manager. Never store a direct pointer to a component but store a component handle instead.


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