Click or drag to resize
DigitalRuneGame Objects

This section explains the concept of a game object.

This topic contains the following sections:

Game objects

Game objects (also called game entities, controllers, or actors) are implemented by the class GameObject. Game objects are containers that contain game logic and have game object properties (see Properties) and game object events (see Events). Game object properties and events can be dynamically added to or removed from any game object at runtime.

Game object properties contain relevant data for scripting, e.g. "Health", "Damage", or reference components of other game services, for example a "RigidBody" for physics, a "Model" for rendering. Game object events describe events that can be raised by the game object, such as the "Enter" event of a Trigger or the "Click" event of a Button.

A game usually contains a number of service, such as Input, AI, Audio, Physics, Graphics, etc. These services usually don't communicate directly with each other. Instead, the game objects act as the glue code that orchestrate the functions of different game services: They read input from the input service, set forces to rigid bodies, read the rigid body positions, and use it to position graphical models in the scene of the renderer.

Game objects can be used as generic containers that are configured in a game editor. But it is also possible to derive from the GameObject class and create specialized game objects. This is, for example, done in the DigitalRune Game UI where the class UIControl derives from GameObject. The DigitalRune game object system was designed to support both cases: Using game objects in an editor or script environment, and using game objects in game libraries.

Note Note

In many game engines, game objects have a few fixed properties, such as a "Position" that defines the 3D position in the scene. Sometimes it also has more predefined properties like, "Shape" (for collision detection), "Model" for rendering, etc. Such a design is adequate for a game editor with limited functionality. It is not suitable for a general purpose game library; because depending on the game, a position of a game object can be defined using a 2D vector, a 3D vector, a parent object - or maybe it should not have a position at all (like a "ScriptObject").

In the DigitalRune Game library game objects are blank slates without predefined properties. This is preferable because it does not impose any restrictions on the architecture of a game.

Naming game objects

Game objects can have a Name. The name can be used to identify a game object and is also helpful for debugging. When a game object is added to a IGameObjectService it must have unique name. See also Game Object Service.

Loading, updating, and unloading game objects

A game object contains the methods Load and Unload. These methods are automatically called when the game object is added to or removed from a IGameObjectService. See also Game Object Service.

The method Update is also call by the IGameObjectService that manages the game object. The method is usually called once per frame to run the game logic of the object.

Derived classes can override the methods OnLoad, OnUpdate, OnUnload and perform the required steps to initialize, update or uninitialize objects.