Bill MacKenty

  Home     Computing     Teaching     Bushcraft     Games     Writing     About  

Entity-Component-System 〈ECS〉

Posted in Computer Science Teaching Diary on 02 - February 2023 at 09:07 PM (one month ago). 91 views.

Different than oop? Read on...

I've learned about the Entity-Component-System (ECS)

Obligatory chatGPT / wikipedia definition: ECS is a pattern for game development that provides a way to organize and structure game logic. It is a way of designing games that separates the data (components) and behavior (systems) of entities.

In an ECS, entities are objects in the game, such as characters or enemies. Components are data structures that define the properties and attributes of an entity, such as its position, health, or sprite. Systems are responsible for updating and manipulating the components of entities.

The separation of data and behavior in an ECS allows for more flexible and modular game development, as it is easier to add or change components and systems without affecting the rest of the code. It also allows for better performance and scalability, as systems can be optimized for processing specific types of components.

Overall, the ECS pattern provides a clean and efficient way to structure game logic, making it a popular choice for game development, especially for large and complex games.

Entity Component System (ECS) is a software architectural pattern mostly used in video game development for the representation of game world objects. An ECS comprises entities composed from components of data, with systems which operate on entities' components.

ECS follows the principle of composition over inheritance, meaning that every entity is defined not by a type hierarchy, but by the components that are associated with it. Systems act globally over all entities which have the required components.

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 labels an entity as possessing a particular aspect, and 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 which acts on all entities with the desired components. For example, a physics system may query for entities having mass, velocity and position components, and iterate over the results doing physics calculations on the sets of components for each entity.

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 commonly stored together in physical memory, enabling efficient memory access for systems which operate over many entities.