My Project
Loading...
Searching...
No Matches
Engine::GameObject Class Reference

Represents an object in the scene. A GameObject can contain multiple components and be part of a hierarchy. More...

#include <GameObject.hpp>

Public Member Functions

 GameObject (const std::string &name="GameObject")
 Creates a GameObject with an optional name.
 ~GameObject ()
 Destructor responsible for cleaning up components.
void Update (float dt)
 Updates all components attached to this GameObject.
const std::string & GetName () const
 Returns the GameObject name.
void SetName (const std::string &newName)
 Sets a new name for the GameObject.
void SetParent (GameObject *newParent)
 Sets the parent GameObject. Updates the hierarchy structure.
GameObjectGetParent () const
 Returns the parent GameObject.
const std::vector< GameObject * > & GetChildren () const
 Returns the children GameObjects.
template<typename T, typename... Args>
T * AddComponent (Args &&... args)
 Adds a new component of type T to this GameObject.
template<typename T>
T * GetComponent ()
 Returns the first component of type T attached to this GameObject.
template<typename T>
bool HasComponent () const
 Checks whether the GameObject contains a component of type T.
template<typename T>
bool RemoveComponent ()
 Removes a component of type T from this GameObject.
const std::vector< Component * > & GetAllComponents () const
 Returns all components attached to the GameObject.
TransformGetTransform ()
 Returns the Transform component of the GameObject. Every GameObject should have one.

Detailed Description

Represents an object in the scene. A GameObject can contain multiple components and be part of a hierarchy.

Constructor & Destructor Documentation

◆ GameObject()

Engine::GameObject::GameObject ( const std::string & name = "GameObject")

Creates a GameObject with an optional name.

Parameters
nameName of the GameObject

◆ ~GameObject()

Engine::GameObject::~GameObject ( )

Destructor responsible for cleaning up components.

Member Function Documentation

◆ AddComponent()

template<typename T, typename... Args>
T * Engine::GameObject::AddComponent ( Args &&... args)
inline

Adds a new component of type T to this GameObject.

Template Parameters
TComponent type
ArgsConstructor arguments
Returns
Pointer to the created component

◆ GetAllComponents()

const std::vector< Component * > & Engine::GameObject::GetAllComponents ( ) const

Returns all components attached to the GameObject.

◆ GetChildren()

const std::vector< GameObject * > & Engine::GameObject::GetChildren ( ) const

Returns the children GameObjects.

◆ GetComponent()

template<typename T>
T * Engine::GameObject::GetComponent ( )
inline

Returns the first component of type T attached to this GameObject.

Template Parameters
TComponent type
Returns
Pointer to the component if found

◆ GetName()

const std::string & Engine::GameObject::GetName ( ) const

Returns the GameObject name.

◆ GetParent()

GameObject * Engine::GameObject::GetParent ( ) const

Returns the parent GameObject.

◆ GetTransform()

Transform * Engine::GameObject::GetTransform ( )

Returns the Transform component of the GameObject. Every GameObject should have one.

Returns
Pointer to the Transform component

◆ HasComponent()

template<typename T>
bool Engine::GameObject::HasComponent ( ) const
inline

Checks whether the GameObject contains a component of type T.

Template Parameters
TComponent type
Returns
True if the component exists

◆ RemoveComponent()

template<typename T>
bool Engine::GameObject::RemoveComponent ( )
inline

Removes a component of type T from this GameObject.

Template Parameters
TComponent type
Returns
True if the component was removed

◆ SetName()

void Engine::GameObject::SetName ( const std::string & newName)

Sets a new name for the GameObject.

Parameters
newNameNew object name

◆ SetParent()

void Engine::GameObject::SetParent ( GameObject * newParent)

Sets the parent GameObject. Updates the hierarchy structure.

Parameters
newParentParent GameObject

◆ Update()

void Engine::GameObject::Update ( float dt)

Updates all components attached to this GameObject.

Parameters
dtDelta time between frames

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