Entity Component System

Entity Component System

Lumberyard uses a component entity system that provides a modular interface for the construction of game elements. Entities are the main objects in the game level and components act as functionalities/behaviors attached to the entities. To add a component to an entity, find the component in the component drop-down menu in the inspector. Components are manipulated from a menu drop down on the entity, and can also be manipulated using typical keyboard shortcuts (copy – Ctrl+c, Paste – Ctrl+v, delete – Delete). They can also be organized by dragging them up/down in the inspector.

Entity in Entity Inspector.

Transformation

Every entity has a transformation component which determines the position, rotation, and scale of the entity. Entities transforms can be altered in the perspective viewport with the mouse, in the transformation component on the entity, as well as at the bottom of the perspective viewport (the x, y, z positions). The transformation component on the entity allows the number to be changed through typing and scrolling the wheel but doesn’t allow dragging the mouse left/right. The component sometimes encounters floating-point errors after the level is saved or the entity is saved as a slice, this is manifested in numbers looking like 179.9999 rather than being 180.

The transformation bus can be connected and and manipulated through code. In Lua, the transform bus can return the transformation matrix of the entity, which requires knowledge of the matrix to be able to use properly. The World TM contains position, rotation, scale, and other information encoded with it. To obtain the right vector of an entity GetColumn(0) of the matrix, GetColumn(1) corresponds to the forward, and the cross of the right and forward gives the up vector; these are really commonly used in game programming.

One of the major issues we encountered was that scaling and rotation in the transformation component don’t always work as expected. Rotating a scaled entity through Lua leads to unpredictable behavior where the rotation angle isn’t equal to the angle input into the rotation function. For example if an entity is scaled and then a script attempts to rotate the entity 90 degrees, the resultant angle is somewhere in between the original angle and 90 but not correlated to the scale of the object. Another effect observed with scaling and rotation, is when an entity was scaled and rotated (in a specific order), the entity obtained a shear, which shouldn’t happen regardless of ordering.

Sidebar