1 Requirements

  1. Tutorial 2 - Creating GameObjects

2 Introduction

This tutorial will show you how to add a Component to an existing GameObject. This can be necessary in different situations: you might add a fire particle to an object starting to burn or a helmet mesh to your character, when he’s equipping the item.

3 Configuring the Component

Adding Components to GameObjects is really simple. From previous tutorials you know every Component needs a map of key-value-pairs defining its settings. Let’s assume we want to add a helmet.mesh to our character. The MeshAppearanceComponent requires five parameters: position, rotation, scale, mesh and visibility. The first three parameters are relative to the main node in the graphic being represented by the player model. Listing 1 shows the complete map creation.

1i6e::api::attributeMap params; 
2params["pos"] = "0.0 0.9, 0.0"; 
3params["rot"] = "1.0 0.0 0.0, 0.0"; 
4params["scale"] = "1.0 1.0 1.0"; 
5params["mesh"] = "Helmet.mesh"; 
6params["visibility"] = "1";
Listing 1: configuring attributeMap

We set position on y-position to 0.9 assuming the character has a height of 1.8 meters and the helmet as well as the player model are centered in origin. So this offset places the helmet to the head of the player. That was the difficult part. Now we have to add a Component with these properties. This will be done as shown in listing 2.

1i6e::api::EngineController::GetSingleton().getObjectFacade()->createComponent(goid, i6e::api::EngineController::GetSingleton().getIDManager()->getID(), "MeshAppearance", params);
Listing 2: create Component

The first parameter is the GameObjects id. You need your GameObject and can get the id using getID(). The second parameter is the id of the newly created Component. Here we call the IDManager to give us the next id. We can enter -1 to invoke the object subsystem to take care of that itself. The third parameter is the registered template for the Component we want to add and the last parameter is our attributeMap.