What's an Entity System?

("Component/Entity System", "CES")

Component/Entity Systems are an architectural pattern used mostly in game development. A CES follows the Composition over Inheritance principle to allow for greater flexibility when defining entities (anything that's part of a game's scene: enemies, doors, bullets) by building out of individual parts that can be mixed-and-matched. This eliminates the ambiguity problems of long inheritance chains and promotes clean design. However, CES systems do incur a small cost to performance.

Concept

A game or application making use of the C/ES pattern involves at least the following:

  1. Entity - A container into which components can be added, usually hierarchical (any Entity can have sub-Entities).
  2. Component - Class of objects through which behaviors, looks and data can be added to an entity.

Whereas in an inheritance-based design, an enemy may have a complex inheritance chain such as Damageable <- Actor <- GroundBasedActor <- Enemy <- ZombieEnemy, in a C/ES-based design you might have a Health component, a GroundBasedMovement component and a ZombieAi component added to an entity named ZombieEnemy.

This eliminates ambiguity issues encountered in an inheritance-based design (should the root be Actor <- DamageableActor or Damageable <- Actor? Should items be implemented twice as PickupActors or DamageablePickupActors?). At the same time, components can be freely combined: a damageable inventory item? add the Collectable and Health components to an entity.

In a pure CES design, entities will not even have positions in the scene. Their location could be provided by an optional Transform or Location component. Their looks (3D model, sprite, icon) are also components.

Rendering and updating may take place either by traversing the entire entity tree (slow), by having entities register themselves to the respective services (service locator hell) or in a hybrid approach where the renderer/clock system remember which components they found in the tree while entities merely provide a change notification if components are added to them or removed from them, allowing the renderer/clock system to re-check that part of the tree (complex). This aspect of the design is however not part of the C/ES pattern.

More Information

A well-known game engine implementing a Component/Entity System is Unity. Its GameObjects are entities with a Transform component built-in and the engine user can write his/her own components in UnityScript, C# or Boo.

The navbar on the left has links to get you started, and a large selection of source code examples.

See also: ES Terminology for a list of terms used within Component/Entity Systems.

We also have a list of basic ES approaches

page revision: 40, last edited: 30 Nov 2014 10:26
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.

AltStyle によって変換されたページ (->オリジナル) /