Main Principles for Using ECS in Game Development

Entity component systems (ECS) is a lot different than making software or building an eCommerce platform. A developer can opt to specialize in eCommerce development services here, but that doesn’t mean that they’ll be prepared for game development.

Game development has many intricacies, from concerns of memory management and system performance to advanced physics requirements. Tonic is a custom software development company.

ECS is just another tool that a game developer can leverage that allows you to process game states in a way that is both flexible and extensible. Game development has a lot of moving parts at any given time. The state of the game is vast, and this may include:

When we mention state, just think of a game with 1,000 enemies. If you kill an enemy, a new state must be made, whether that means a respawn timer is initiated, or the enemy remains dead.

Each object in the environment has a state, and behavior has to be added to each object in a way that can be managed. The data must also be stored in a way that is manageable. There is a lot that goes into a game, and ECS provides solutions that can help make state management easier.

Entity

An Entity just like these characters from certain Nintendo titles…

Entity, or the E in ECS is an item, character or object. The bullets a character shoots or the vehicles they drive are entities. The character is also an entity that will be comprised of their own:

Entity management requires a way to store information that can easily be tied to the entity using the unique ID. The information typically exists in a database so that it can be retrieved. The data may also persist in memory that is faster to access than a database in the middle of gameplay. That’s why import records is crucial.

The data in memory will eventually be saved to a database or file when the game’s state is saved.

Component

There is a LOT of data in game development…

The component, or the C in ECS is difficult to understand if you don’t have a background in development. Entities, or the objects and characters we just discussed, have a lot of data about them that needs to be stored.

Let’s imagine a dog that can eat, attack, lose or gain weight, or lunge.

Raw data about the dog may be held in a component so that the dog can be rendered to the screen.

This information, or the data relating to entities, are held in a component.

System

The final part of ECS is the system. Entities need logic that allows the entities to act in a certain way. A system may include speed for two objects so that when they’re moving towards one another their position changes accordingly.

Since entities may have different velocities, the system will need to update position accordingly and modify it according to the entity’s velocity.

Behavior logic resides in the system.

Objects and Entities

There are many programs to use for game development…

In object-oriented programming, you can create an object for firearms. The components would be created and assigned an identifier that ties both the components and entity together. Components are often stored in a relational database and will use rows to hold all of the information.

Joins can be used to join the entity with its respective components using the unique ID assigned.

The system’s role in the process is to query all of the necessary components and use this data in a meaningful way to execute certain logic.

Game development is complex, but ECS solves many of the issues with state that developers come across. A lot of developers will only create as many items that need state as required because state can be very difficult to maintain in a way that is logical, functional and doesn’t require massive amounts of memory usage.

State is best when it is able to remain in its raw state and is searchable.

ECS is just one of the many ways that developers can manage entities and all the components and systems that bring them to life. ECS is a different approach that doesn’t rely as heavily on the object-oriented models that take up the majority of coding.

This article contains sponsored links.

Exit mobile version