Component Class Reference

Description

Components represent primary logic elements in the scene.

They are attached to scene objects.

You should implement some or all of update/onCreated/onInitialized/onEnabled/onDisabled/onTransformChanged/ onDestroyed methods to implement the relevant component logic. Avoid putting logic in constructors or destructors.

Components can be in different states. These states control which of the events listed above trigger:

  • Running - Scene manager is sending out events.
  • Paused - Scene manager is sending out all events except per-frame update().
  • Stopped - Scene manager is not sending out events except for onCreated/onDestroyed.

These states can be changed globally though SceneManager and affect all components. Individual components can override these states in two ways:

  • Set the ComponentFlag::AlwaysRun to true and the component will always stay in Running state, regardless of state set in SceneManager. This flag should be set in constructor and not change during component lifetime.
  • If the component's parent SceneObject is inactive (SceneObject::setActive(false)), or any of his parents are inactive, then the component is considered to be in Stopped state, regardless whether the ComponentFlag::AlwaysRun flag is set or not.

Inherits GameObject.

Inherited by CAnimation, CAudioListener, CAudioSource, CBone, CCamera, CCharacterController, CCollider, CGUIWidget, CJoint, CLight, CProfilerOverlay, CReflectionProbe, CRenderable, CRigidbody, CSkybox, and ManagedComponent.

Methods

HSceneObject sceneObject () const
 Returns the SceneObject this Component is assigned to. More...
 
HSceneObject SO () const
 Returns the SceneObject this Component is assigned to. More...
 
HComponent getHandle () const
 Returns a handle to this object. More...
 
virtual void update ()
 Called once per frame. More...
 
virtual bool calculateBounds (Bounds &bounds)
 Calculates bounds of the visible contents represented by this component (for example a mesh for Renderable). More...
 
virtual bool typeEquals (const Component &other)
 Checks if this and the provided component represent the same type. More...
 
void destroy (bool immediate=false)
 Removes the component from parent SceneObject and deletes it. More...
 
RTTITypeBasegetRTTI () const override
 Returns an interface you can use to access class' Run Time Type Information. More...
 
Internal
virtual void _instantiate ()
 Construct any resources the component needs before use. More...
 
void setNotifyFlags (TransformChangedFlags flags)
 Sets new flags that determine when is onTransformChanged called. More...
 
TransformChangedFlags _getNotifyFlags () const
 Gets the currently assigned notify flags. More...
 
- Methods inherited from GameObject
UINT64 getInstanceId () const
 Returns the unique instance ID of the GameObject. More...
 
UINT32 getLinkId () const
 Returns an ID that identifies a link between this object and its equivalent in the linked prefab. More...
 
const StringgetName () const
 Gets the name of the object. More...
 
void setName (const String &name)
 Sets the name of the object. More...
 
void _setIsDestroyed ()
 Marks the object as destroyed. More...
 
bool _getIsDestroyed () const
 Checks if the object has been destroyed. More...
 
void _setLinkId (UINT32 id)
 Changes the prefab link ID for this object. More...
 
virtual void _setInstanceData (GameObjectInstanceDataPtr &other)
 Replaces the instance data with another objects instance data. More...
 
virtual GameObjectInstanceDataPtr _getInstanceData () const
 Returns instance data that identifies this GameObject and is used for referencing by game object handles. More...
 
- Methods inherited from IReflectable
bool isDerivedFrom (RTTITypeBase *base)
 Returns true if current RTTI class is derived from base (Or if it is the same type as base). More...
 
UINT32 getTypeId () const
 Returns an unique type identifier of the class. More...
 
const StringgetTypeName () const
 Returns the type name of the class. More...
 

Static methods

static RTTITypeBasegetRTTIStatic ()
 
- Static methods inherited from GameObject
static RTTITypeBasegetRTTIStatic ()
 
- Static methods inherited from IReflectable
static Vector< RTTITypeBase * > & getDerivedClasses ()
 Returns all classes deriving directly from IReflectable. More...
 
static SPtr< IReflectablecreateInstanceFromTypeId (UINT32 rttiTypeId)
 Creates an empty instance of a class from a type identifier. More...
 
static void _registerDerivedClass (RTTITypeBase *derivedClass)
 Called by each type deriving from IReflectable, on program load. More...
 
static RTTITypeBase_getRTTIfromTypeId (UINT32 rttiTypeId)
 Returns class' RTTI type from type id. More...
 
static bool _isTypeIdDuplicate (UINT32 typeId)
 Checks if the provided type id is unique. More...
 
static void _checkForCircularReferences ()
 Iterates over all RTTI types and reports any circular references (for example one type having a field referencing another type, and that type having a field referencing the first type). More...
 
static RTTITypeBasegetRTTIStatic ()
 Returns an interface you can use to access class' Run Time Type Information. More...
 

Method documentation

TransformChangedFlags _getNotifyFlags ( ) const

Gets the currently assigned notify flags.

See _setNotifyFlags().

virtual void _instantiate ( )
virtual

Construct any resources the component needs before use.

Called when the parent scene object is instantiated. A non-instantiated component shouldn't be used for any other purpose than serialization.

Reimplemented in ManagedComponent.

virtual bool calculateBounds ( Bounds bounds)
virtual

Calculates bounds of the visible contents represented by this component (for example a mesh for Renderable).

Parameters
[in]boundsBounds of the contents in world space coordinates.
Returns
True if the component has bounds with non-zero volume, otherwise false.

Reimplemented in ManagedComponent, and CRenderable.

void destroy ( bool  immediate = false)

Removes the component from parent SceneObject and deletes it.

All the references to this component will be marked as destroyed and you will get an exception if you try to use them.

Parameters
[in]immediateIf true the destruction will be performed immediately, otherwise it will be delayed until the end of the current frame (preferred option).
void destroyInternal ( GameObjectHandleBase handle,
bool  immediate = false 
)
overrideprotectedvirtual

Destroys this component.

Parameters
[in]handleGame object handle this this object.
[in]immediateIf true, the object will be deallocated and become unusable right away. Otherwise the deallocation will be delayed to the end of frame (preferred method).
Note
Unlike destroy(), does not remove the component from its parent.

Implements GameObject.

HComponent getHandle ( ) const

Returns a handle to this object.

RTTITypeBase* getRTTI ( ) const
overridevirtual

Returns an interface you can use to access class' Run Time Type Information.

Note
You must derive your own version of RTTITypeBase, in which you may encapsulate all reflection specific operations.

Reimplemented from GameObject.

Reimplemented in CRigidbody, ManagedComponent, CGUIWidget, CReflectionProbe, CRenderable, CSkybox, CSliderJoint, CPlaneCollider, CSphereCollider, CSphericalJoint, WindowFrameWidget, and CProfilerOverlay.

UINT32 getSceneManagerId ( ) const
protected

Returns an index that unique identifies a component with the SceneManager.

bool hasFlag ( ComponentFlag  flag) const
protected

Checks if the component has a certain flag enabled.

virtual void onCreated ( )
protectedvirtual

Called once when the component has been created.

Called regardless of the state the component is in.

Reimplemented in ManagedComponent.

virtual void onDestroyed ( )
protectedvirtual

Called once just before the component is destroyed.

Called regardless of the state the component is in.

Reimplemented in CCamera, CRigidbody, CAnimation, ManagedComponent, CCharacterController, CLight, CAudioSource, CCollider, CReflectionProbe, CGUIWidget, CRenderable, CJoint, CBone, and CAudioListener.

virtual void onDisabled ( )
protectedvirtual

Called every time a component is placed into the Stopped state.

This includes component destruction if component wasn't already in Stopped state during destruction. When called during destruction it is called before onDestroyed.

Reimplemented in CRigidbody, CAnimation, ManagedComponent, CCharacterController, CAudioSource, CCollider, CJoint, CBone, and CAudioListener.

virtual void onEnabled ( )
protectedvirtual

Called every time a component leaves the Stopped state.

This includes component creation if requirements for leaving the Stopped state are met. When called during creation it is called after onInitialized.

Reimplemented in CRigidbody, CAnimation, ManagedComponent, CCharacterController, CAudioSource, CCollider, CJoint, CBone, and CAudioListener.

virtual void onInitialized ( )
protectedvirtual

Called once when the component first leaves the Stopped state.

This includes component creation if requirements for leaving Stopped state are met, in which case it is called after onCreated.

Reimplemented in CCamera, CRigidbody, CAnimation, ManagedComponent, CCharacterController, CLight, CAudioSource, CCollider, CReflectionProbe, CRenderable, CJoint, CSkybox, and CAudioListener.

virtual void onTransformChanged ( TransformChangedFlags  flags)
protectedvirtual

Called when the component's parent scene object has changed.

Not called if the component is in Stopped state. Also only called if necessary notify flags are set via _setNotifyFlags().

Reimplemented in CRigidbody, CAnimation, CCharacterController, CAudioSource, CCollider, CJoint, CBone, and CAudioListener.

HSceneObject sceneObject ( ) const

Returns the SceneObject this Component is assigned to.

void setFlag ( ComponentFlag  flag,
bool  enabled 
)
protected

Enables or disabled a flag controlling component's behaviour.

void setNotifyFlags ( TransformChangedFlags  flags)

Sets new flags that determine when is onTransformChanged called.

void setSceneManagerId ( UINT32  id)
protected

Sets an index that uniquely identifies a component with the SceneManager.

HSceneObject SO ( ) const

Returns the SceneObject this Component is assigned to.

bool supportsNotify ( TransformChangedFlags  flags) const
protected

Checks whether the component wants to received the specified transform changed message.

virtual bool typeEquals ( const Component other)
virtual

Checks if this and the provided component represent the same type.

Note
RTTI type cannot be checked directly since components can be further specialized internally for scripting purposes.

Reimplemented in ManagedComponent.

virtual void update ( )
virtual

Called once per frame.

Only called if the component is in Running state.

Reimplemented in CCamera, ManagedComponent, CAudioSource, CLight, CReflectionProbe, CRenderable, CGUIWidget, CSkybox, CAudioListener, and CProfilerOverlay.