Entity Component System

What is Entity-Component-System?

Entity-Component–System (ECS) is an architectural pattern. This pattern is widely used in game application development. ECS follows the composition over the inheritance principle, which offers better flexibility and helps you to identify entities where all objects in a game's scene are considered an entity.

ECS programming is a method of writing code that provides high performance by default.

This system consists of three terms.

  1. Entity
  2. Component
  3. System

Let us learn this concept in detail:

In this Entity-Component System tutorial, you will learn:

What is an Entity?

An entity is a distinct object representing an actor in a simulated space. It has not actual data or behavior. This Component gives an entity its data. It is typically a strut or dictionary.

For example, if we are simulating a game's universe Minecraft, all the visible, tangible 'things' in the game universe like are counted in entities.

What is a Component?

A Component is a singular behavior ascribed to an entity. The name of an element should ideally communicate what behavior the entity will exhibit. However, the component itself has no behavior. They are reusable modules that are attached to entities. The component provides appearance, behavior, and functionality.

All logic is implemented using components which helps you to define different types of objects by mixing and configuring components.

What is the System?

A system will iterate many components to perform low-level

functions such as rendering graphics, performing physics

calculations or pathfinding. It offers global scope, management, and services for classes of components.

However, systems are not optional, but we can use them to separate logic and data. It also helps you handle the logical components, act as data containers.

Examples

Composition

A composition is an element you could attach more components to add additional appearance, behaviour, or functionality. You can also update the component values to configure the entity.

Advantage of ECS

Here are advantages of using ECS in programming:

Disadvantages of using ECS

Here, are some drawback of using ECS

Entity Component System Example

Let us look at the example of a bunny:

See the dashed box around these components. That is the bunny entity - nothing than a container of components. You can also define entities as an aggregation of any subset of components.

You can see the above-given image. It is one of the bunny entities - nothing more than a container of components. You can define entities as an aggregation of any subset of components, like Carrot:

Data flow in ECS:

Systems behaviour is ECS model is change from one state to another.

Let us understand using this example:

Behaviors: "A bunny sitting on a tree falls due to gravity."

How to Implement the above behavior?

You can make it by z value of more than 0 which decreases over time to 0.

Behavior: "Living beings age."

Let see how you can implement this behavior?

You can make it so that Living Components have age value, which increases over time.

Summary:

 

YOU MIGHT LIKE: