Search This Blog

A short Introduction to ECS

ECS is a architectural pattern used mostly in computer
games that allows for a greater flexibility in categorizing entities
in games (ex : player, enemy, weapon, etc.), and separating the data
(the components) from the actual code(the system).

The
data oriented design is repeatedly gaining ground in the game
development industry over traditional OOP because it is more
efficient, and if done right it scales better on bigger projects with
bigger teams, meaning it's much easier to find bugs, increase
performance or to add new systems late in the development process, or
even after the game is released.

ECS
and OOP are mutually exclusive. Some people may argue that elements
of OOP can be integrate successfully into ECS paradigm, but the
general consensus, and my observations so far is that if you really
want profit from the ECS advantages you need to leave all the OOP
techniques behind as combining them will not only make things murkier
for you and potentially you colleagues(if you work in a team),
but can also lead you to pitfalls that will break the ECS.

The
pure ECS architectures gives you a clear separation between data and
code, letting you optimize for performance and build more complex
interactions.

What
is an entity?

An entity is any non abstract in-game object, like a
car, or a weapon, or a bullet, etc. Entities have no data and no
methods attached to them, you can think of them more like tags.

What
is a component?

A component is a data container. Any in-game object has
multiple aspects to it , that define what it is and how it interacts
with the world.

For example : the player might:

move
with a certain speed - speedComponent

it
is controlled by a player - inputComponent

be
able to colide with other objects - rigidBodyComponent

have
a position and a rotation - transformComponent

have
animations - animationComponent

The OOP paradigm does not have concept of many aspects.
The properties are hard coded into the class definition.

Sure you can use inheritance to define a enemy and then
from that to define specific types of enemies, but you can't use
properties from the player for example, witch in games can sometimes
be very useful. For example: you take controll over an enemy (by
adding to that enemy the input component).

What's
a System?

A system provides the implementation of components, but
it does it differently compared with the OOP witch would be that for
each component to have it own methods that are then externally
invoked.

The way that ECS handles it is to have continuously
running systems that have they're own methods witch operate on
components.

The differences is that in OOP theoretically if you have
100 units on the screen, each have they're own methods, where by in
ECS you have an external system of methods that operate on the
components (aka the data) of those units.

Unity's
new focus on ECS!

Unity
is already starting to implement the ECS model into they're engine
and has big plans for it witch in conjunction with they're new job
system that they're building should bring big improvements not only
to the performance of future games, but also to the scalability of
said games, bringing into focus a new era for building games from
huge 3A titles to tiny messenger apps or web apps.

And
that the most important part of why they're transitioning to the ECS
system, because it will let them and us to modularize out code so
only what's essential for our projects is include increasing
performance in big games, and decreasing file size and loading times
in small games.