ArticleslgStudy

computer science

Entity component system

Entity component system is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Entity component system rather than just read about it. In short: The Entity component system (ECS) is a software architectural pattern following a data-oriented architectural style. It is most associated with video game development for the representation of game world objects, and is often characterized by the use of structures of arrays to improve runtime performance.

Entity component system — main illustration
Entity component system — illustration

Key takeaways

  • Entity component system belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Entity component system to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Entity component system from memory before moving on to harder problems.

Reference excerpt

The Entity component system (ECS) is a software architectural pattern following a data-oriented architectural style. It is most associated with video game development for the representation of game world objects, and is often characterized by the use of structures of arrays to improve runtime performance. ECS prioritizes composition over inheritance. Every entity is defined not by a type hierarchy, but by the components associated with it. Systems act globally over all entities that have the required components. For example, a food system might iterate through every entity with a relevant component tracking hunger, and act on them to push them a little away from satiation at time intervals. Entities lacking the component like terrain or items would be naturally ignored by the food system. Due to an ambiguity in the English language, an interpretation of the name is that an ECS is a system comprising entities and components. In the 2002 talk at GDC, Scott Bilas compared a C++ object system and his new custom component system. This is consistent with a traditional use of system terms in general systems engineering with Common Lisp Object System and type system as examples. While historically mostly found video game development, the pattern can be useful in other domains, such as in robotics simulators like Gazebo. Recent research has been published that attempts to formalize the ECS pattern as a computational model.

Characteristics ECS combines orthogonal, well-established ideas in general computer science and programming language theory. For example, components can be seen as a mixin idiom in various programming languages. Components are a specialized case under the general delegation approach and meta-object protocol. That is, any complete component object system can be expressed with the templates and empathy model within The Orlando Treaty vision of object-oriented programming.

Entity An entity represents a general-purpose object. In a game engine context, for example, every coarse game object is represented as an entity. Usually, it only consists of a unique ID. Implementations typically use a plain integer for this. Component A component characterizes an entity as possessing a particular aspect, and (the component) holds the data needed to model that aspect. For example, every game object that can take damage might have a Health component associated with its entity. Implementations typically use structs, classes, or associative arrays. System A system is a process that acts on all entities with the desired components. For example, a physics system may query for entities having mass, velocity and position components, iterate over the results, and do physics calculations for each entity using the set of components. The behavior of an entity can be changed at runtime by systems that add, remove or modify components. This eliminates the ambiguity problems of deep and wide inheritance hierarchies often found in object-oriented programming techniques that are difficult to understand, maintain, and extend. Common ECS approaches are highly compatible with, and are often combined with, data-oriented design techniques. Data for all instances of a component are contiguously stored together in physical memory, enabling efficient memory access for systems that operate over many entities.

Formal Model Although ECS originated as an industry practise, recent academic work has proposed formal models of ECS execution. These models generally define an ECS world as:

A set of entities, which provide identity; A collection of component types that represent data; Associations between entities and component instances; Systems that execute computations over entities matching specified component requirements. Under this interpretation, systems do not directly own data. Instead, they operate over subsets of entities selected by component-based queries. ECS programs can therefore be viewed as compositions of transformations over a shared, non-hierarchical data store. Formalizations of ECS have also modeled operations such as entity creation, component addition and removal, system execution, and migration between storage structures as state transitions, providing a basis for reasoning about behavior and correctness.

Relationship to Data-Oriented Design ECS is commonly associated with data-oriented design (DOD), a software design philosophy that emphasizes data layout and memory access patterns as primary design concerns. While ECS and data-oriented design are distinct concepts, many ECS frameworks employ data-oriented storage strategies, such as structure-of-arrays layouts and archetype-based organization, to improve cache utilization and parallel processing efficiency. Consequently, ECS is often regarded as a practical architectural realization of data-oriented design principles.

History In 1963, Ivan Sutherland's Sketchpad stored the visual elements of a drawing using an early form of an ECS. Instead of encapsulating points in different objects (e.g. lines, circles, rectangles) points were stored in a ring buffer, and visual elements were only referencing them. When moving a point, this allowed updating all the shapes and constraints using it. In 1998, Thief: The Dark Project pioneered an ECS. The engine was later used for its sequel, as well as System Shock 2. In 2002, Scott Bilas of Gas Powered Games (Dungeon Siege) gave a seminal talk on ECS. This inspired numerous later well-known implementations. In early January 2007, Mick West who worked on the Tony Hawk series, shared his experiences on the process of ECS adoption at Neversoft. Also in 2007, the team working on Operation Flashpoint: Dragon Rising experimented with ECS designs, including those inspired by Bilas/Dungeon Siege, and Adam Martin later wrote a detailed account of ECS design, including definitions of core terminology and concepts. In particular, Martin's work popularized the ideas of systems as a first-class element, entities as identifiers, components as raw data, and code stored in systems, not in components or entities. In 2015, Apple Inc. introduced GameplayKit, an API framework for iOS, macOS and tvOS game development that includes an implementation of ECS. In October 2018 the company Unity released its megacity demo that utilized a tech stack built on an ECS. Unity's ECS runs on a powerful optimized architecture known as DOTS, which "empowers creators to scale processing in a highly performant manner".

… excerpt ends here. Continue reading the full article.

Illustrations

Entity component system: A simple Entity–Component–System layout.
A simple Entity–Component–System layout.

Worked examples

Example 1 — a first encounter with Entity component system

Start with the simplest possible case. Write down what Entity component system claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Entity component system before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Entity component system ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Entity component system

In research
Entity component system appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Entity component system in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Entity component system is common in secondary-school and first-year university syllabi. It links to neighbouring topics Architectural pattern (computer science), Data-oriented programming, Software design patterns, so understanding it makes those chapters shorter.
In everyday life
Look for Entity component system outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Entity component system” →

How to study Entity component system in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Entity component system means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Entity component system out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Entity component system in simple terms?

The Entity component system (ECS) is a software architectural pattern following a data-oriented architectural style. It is most associated with video game development for the representation of game world objects, and is often characterized by the use of structures of arrays to improve runtime perfo…

Why does Entity component system matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Entity component system?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Entity component system.

Tags

  • Architectural pattern (computer science)
  • Data-oriented programming
  • Software design patterns

Keep exploring