Skip to content

GameObject

Shahriar Shahrabi edited this page May 11, 2020 · 2 revisions

GameObject

A GameObject is a container to group together a series of behaviors. Given a transform, it has a position in the world and can act as the container for physical things such as meshes. However it can also be a more abstracted object, like a manager that registers inputs. GameObjects are added to a Scene and their relevant functions are called by the scene at the appropriate time. The GameObject in turn propagates the same calls to its Components.

GameObject's life time is controlled by the Scene. The Scene is responsible for deleting them and freeing the memory. The GameObjects in turns are responsible for the memory of its Components. The Components memory is free upon the destruction of the GameObject. For that reason the Components should be unique and shouldn't be shared between several GameObjects.

Its main functions are:

Function name Purpose
OnStart() For initialization of game logic and values after the scene construction
OnUpdate() For running the main CPU orientated Game logic
OnRender() Used for rendering calls to the RHI after the game logic
OnGui() Used for GUI rendering as well as GUI logic
GetComponent<T>() A templated function that looks for a component of a certain type attached to the gameObject. Null if the component is not there
AddComponent<T>(T*) Used to register a Component by a Gameobject, pass on a pointer to the constructed component

Its main member values are:

Member Purpose
string name Used for differentiating between the gameobjects
Clone this wiki locally