ezEngine  Milestone 9
ezGameObject Class Reference

This class represents an object inside the world. More...

#include <GameObject.h>

Classes

class  ChildIterator
 
class  ConstChildIterator
 Iterates over all children of one object. More...
 

Public Types

enum  TransformPreservation { PreserveLocal, PreserveGlobal }
 Defines during re-parenting what transform is going to be preserved.
 

Public Member Functions

ezGameObjectHandle GetHandle () const
 Returns a handle to this object.
 
void MakeDynamic ()
 Makes this object and all its children dynamic. Dynamic objects might move during runtime.
 
void MakeStatic ()
 Makes this object static. Static objects don't move during runtime.
 
bool IsDynamic () const
 Returns whether this object is dynamic.
 
bool IsStatic () const
 Returns whether this object is static.
 
void Activate ()
 Activates the object and all its components.
 
void Deactivate ()
 Deactivates the object and all its components.
 
bool IsActive () const
 Returns whether this object is active.
 
void SetName (const char *szName)
 Sets the name to identify this object. Does not have to be a unique name.
 
void SetName (const ezHashedString &sName)
 
const char * GetName () const
 
bool HasName (const ezTempHashedString &name) const
 
void SetGlobalKey (const char *szGlobalKey)
 Sets the global key to identify this object. Global keys must be unique within a world.
 
void SetGlobalKey (const ezHashedString &sGlobalKey)
 
const char * GetGlobalKey () const
 
void SetParent (const ezGameObjectHandle &parent, ezGameObject::TransformPreservation preserve=TransformPreservation::PreserveGlobal)
 Sets the parent of this object to the given.
 
ezGameObjectGetParent ()
 Gets the parent of this object or nullptr if this is a top-level object.
 
const ezGameObjectGetParent () const
 Gets the parent of this object or nullptr if this is a top-level object.
 
void AddChild (const ezGameObjectHandle &child, ezGameObject::TransformPreservation preserve=TransformPreservation::PreserveGlobal)
 Adds the given object as a child object.
 
void AddChildren (const ezArrayPtr< const ezGameObjectHandle > &children, ezGameObject::TransformPreservation preserve=TransformPreservation::PreserveGlobal)
 Adds the given objects as child objects.
 
void DetachChild (const ezGameObjectHandle &child, ezGameObject::TransformPreservation preserve=TransformPreservation::PreserveGlobal)
 Detaches the given child object from this object and makes it a top-level object.
 
void DetachChildren (const ezArrayPtr< const ezGameObjectHandle > &children, ezGameObject::TransformPreservation preserve=TransformPreservation::PreserveGlobal)
 Detaches the given child objects from this object and makes them top-level objects.
 
ezUInt32 GetChildCount () const
 Returns the number of children.
 
ChildIterator GetChildren ()
 Returns an iterator over all children of this object.
 
ConstChildIterator GetChildren () const
 Returns an iterator over all children of this object.
 
ezGameObjectFindChildByName (const ezTempHashedString &name, bool bRecursive=true)
 Searches for a child object with the given name. Optionally traverses the entire hierarchy. More...
 
ezGameObjectFindChildByPath (const char *path)
 Searches for a child using a path. Every path segment represents a child with a given name. More...
 
ezGameObjectSearchForChildByNameSequence (const char *szObjectSequence, const ezRTTI *pExpectedComponent=nullptr)
 Searches for a child similar to FindChildByName() but allows to search for multiple names in a sequence. More...
 
void SearchForChildrenByNameSequence (const char *szObjectSequence, const ezRTTI *pExpectedComponent, ezHybridArray< ezGameObject *, 8 > &out_Objects)
 Same as SearchForChildByNameSequence but returns ALL matches, in case the given path could mean multiple objects. More...
 
ezWorldGetWorld ()
 
const ezWorldGetWorld () const
 
void SetLocalPosition (ezVec3 position)
 Changes the position of the object local to its parent. More...
 
ezVec3 GetLocalPosition () const
 
void SetLocalRotation (ezQuat rotation)
 
ezQuat GetLocalRotation () const
 
void SetLocalScaling (ezVec3 scaling)
 
ezVec3 GetLocalScaling () const
 
void SetLocalUniformScaling (float scaling)
 
float GetLocalUniformScaling () const
 
void SetGlobalPosition (const ezVec3 &position)
 
ezVec3 GetGlobalPosition () const
 
void SetGlobalRotation (const ezQuat rotation)
 
ezQuat GetGlobalRotation () const
 
void SetGlobalScaling (const ezVec3 scaling)
 
ezVec3 GetGlobalScaling () const
 
void SetGlobalTransform (const ezTransform &transform)
 
ezTransform GetGlobalTransform () const
 
void SetLocalPosition (const ezSimdVec4f &position)
 
const ezSimdVec4fGetLocalPositionSimd () const
 
void SetLocalRotation (const ezSimdQuat &rotation)
 
const ezSimdQuatGetLocalRotationSimd () const
 
void SetLocalScaling (const ezSimdVec4f &scaling)
 
const ezSimdVec4fGetLocalScalingSimd () const
 
void SetLocalUniformScaling (const ezSimdFloat &scaling)
 
ezSimdFloat GetLocalUniformScalingSimd () const
 
void SetGlobalPosition (const ezSimdVec4f &position)
 
const ezSimdVec4fGetGlobalPositionSimd () const
 
void SetGlobalRotation (const ezSimdQuat &rotation)
 
const ezSimdQuatGetGlobalRotationSimd () const
 
void SetGlobalScaling (const ezSimdVec4f &scaling)
 
const ezSimdVec4fGetGlobalScalingSimd () const
 
void SetGlobalTransform (const ezSimdTransform &transform)
 
const ezSimdTransformGetGlobalTransformSimd () const
 
ezVec3 GetGlobalDirForwards () const
 Returns the 'forwards' direction of the world's ezCoordinateSystem, rotated into the object's global space.
 
ezVec3 GetGlobalDirRight () const
 Returns the 'right' direction of the world's ezCoordinateSystem, rotated into the object's global space.
 
ezVec3 GetGlobalDirUp () const
 Returns the 'up' direction of the world's ezCoordinateSystem, rotated into the object's global space.
 
void SetVelocity (const ezVec3 &vVelocity)
 Sets the object's velocity. More...
 
ezVec3 GetVelocity () const
 Returns the velocity of the object in units per second. This is not only the diff between last frame's position and this frame's position, but also the time difference is divided out.
 
void UpdateGlobalTransform ()
 Updates the global transform immediately. Usually this done during the world update after the "Post-async" phase.
 
ezBoundingBoxSphere GetLocalBounds () const
 
ezBoundingBoxSphere GetGlobalBounds () const
 
const ezSimdBBoxSphereGetLocalBoundsSimd () const
 
const ezSimdBBoxSphereGetGlobalBoundsSimd () const
 
void UpdateLocalBounds ()
 Invalidates the local bounds and sends a message to all components so they can add their bounds.
 
void UpdateGlobalTransformAndBounds ()
 Updates the global transform and bounds immediately. Usually this done during the world update after the "Post-async" phase.
 
ezSpatialDataHandle GetSpatialData () const
 Returns a handle to the internal spatial data.
 
template<typename T >
bool TryGetComponentOfBaseType (T *&out_pComponent)
 Tries to find a component of the given base type in the objects components list and returns the first match.
 
template<typename T >
bool TryGetComponentOfBaseType (const T *&out_pComponent) const
 Tries to find a component of the given base type in the objects components list and returns the first match.
 
bool TryGetComponentOfBaseType (const ezRTTI *pType, ezComponent *&out_pComponent)
 Tries to find a component of the given base type in the objects components list and returns the first match.
 
bool TryGetComponentOfBaseType (const ezRTTI *pType, const ezComponent *&out_pComponent) const
 Tries to find a component of the given base type in the objects components list and returns the first match.
 
template<typename T >
void TryGetComponentsOfBaseType (ezHybridArray< T *, 8 > &out_components)
 Tries to find components of the given base type in the objects components list and returns all matches.
 
template<typename T >
void TryGetComponentsOfBaseType (ezHybridArray< const T *, 8 > &out_components) const
 Tries to find components of the given base type in the objects components list and returns all matches.
 
void TryGetComponentsOfBaseType (const ezRTTI *pType, ezHybridArray< ezComponent *, 8 > &out_components)
 Tries to find components of the given base type in the objects components list and returns all matches.
 
void TryGetComponentsOfBaseType (const ezRTTI *pType, ezHybridArray< const ezComponent *, 8 > &out_components) const
 Tries to find components of the given base type in the objects components list and returns all matches.
 
ezArrayPtr< ezComponent *const > GetComponents ()
 Returns a list of all components attached to this object.
 
ezArrayPtr< const ezComponent *const > GetComponents () const
 Returns a list of all components attached to this object.
 
bool SendMessage (ezMessage &msg)
 Sends a message to all components of this object.
 
bool SendMessage (ezMessage &msg) const
 Sends a message to all components of this object.
 
bool SendMessageRecursive (ezMessage &msg)
 Sends a message to all components of this object and then recursively to all children.
 
bool SendMessageRecursive (ezMessage &msg) const
 Sends a message to all components of this object and then recursively to all children.
 
void PostMessage (const ezMessage &msg, ezObjectMsgQueueType::Enum queueType, ezTime delay=ezTime()) const
 Queues the message for the given phase. The message is processed after the given delay in the corresponding phase.
 
void PostMessageRecursive (const ezMessage &msg, ezObjectMsgQueueType::Enum queueType, ezTime delay=ezTime()) const
 Queues the message for the given phase. The message is processed after the given delay in the corresponding phase.
 
ezTagSetGetTags ()
 Returns the tag set associated with this object.
 
const ezTagSetGetTags () const
 
const ezUInt16 & GetTeamID () const
 Returns the 'team ID' that was given during creation (/see ezGameObjectDesc) More...
 
void SetTeamID (ezUInt16 id)
 Changes the team ID for this object and all children recursively.
 
template<typename T >
EZ_ALWAYS_INLINE bool TryGetComponentOfBaseType (T *&out_pComponent)
 
template<typename T >
EZ_ALWAYS_INLINE bool TryGetComponentOfBaseType (const T *&out_pComponent) const
 

Friends

class ezWorld
 
class ezInternal::WorldData
 
class ezMemoryUtils
 
class ezComponentManagerBase
 
class ezGameObjectTest
 

Detailed Description

This class represents an object inside the world.

Game objects only consists of hierarchical data like transformation and a list of components. You cannot derive from the game object class. To add functionality to an object you have to attach components to it. To create an object instance call CreateObject on the world. Never store a direct pointer to an object but store an object handle instead.

See also
ezWorld
ezComponent

Member Function Documentation

◆ FindChildByName()

ezGameObject * ezGameObject::FindChildByName ( const ezTempHashedString name,
bool  bRecursive = true 
)

Searches for a child object with the given name. Optionally traverses the entire hierarchy.

Test:
Needs a unit test

◆ FindChildByPath()

ezGameObject * ezGameObject::FindChildByPath ( const char *  path)

Searches for a child using a path. Every path segment represents a child with a given name.

Paths are separated with single slashes: / When an empty path is given, 'this' is returned. When on any part of the path the next child cannot be found, nullptr is returned. This function expects an exact path to the destination. It does not search the full hierarchy for the next child, as SearchChildByNameSequence() does.

Test:
Needs a unit test

◆ GetTeamID()

const ezUInt16& ezGameObject::GetTeamID ( ) const
inline

Returns the 'team ID' that was given during creation (/see ezGameObjectDesc)

It is automatically passed on to objects created by this object. This makes it possible to identify which player or team an object belongs to.

◆ SearchForChildByNameSequence()

ezGameObject * ezGameObject::SearchForChildByNameSequence ( const char *  szObjectSequence,
const ezRTTI pExpectedComponent = nullptr 
)

Searches for a child similar to FindChildByName() but allows to search for multiple names in a sequence.

The names in the sequence are separated with slashes. For example, calling this with "a/b" will first search the entire hierarchy below this object for a child named "a". If that is found, the search continues from there for a child called "b". If such a child is found and pExpectedComponent != nullptr, it is verified that the object contains a component of that type. If it doesn't the search continues (including back-tracking).

Test:
Needs a unit test

◆ SearchForChildrenByNameSequence()

void ezGameObject::SearchForChildrenByNameSequence ( const char *  szObjectSequence,
const ezRTTI pExpectedComponent,
ezHybridArray< ezGameObject *, 8 > &  out_Objects 
)

Same as SearchForChildByNameSequence but returns ALL matches, in case the given path could mean multiple objects.

Test:
Needs a unit test

◆ SetLocalPosition()

EZ_ALWAYS_INLINE void ezGameObject::SetLocalPosition ( ezVec3  position)

Changes the position of the object local to its parent.

Note
The rotation of the object itself does not affect the final global position! The local position is always in the space of the parent object. If there is no parent, local position and global position are identical.

◆ SetVelocity()

EZ_ALWAYS_INLINE void ezGameObject::SetVelocity ( const ezVec3 vVelocity)

Sets the object's velocity.

This is used for some rendering techniques or for the computation of sound Doppler effect. It has no effect on the object's subsequent position.


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