Since Unity 2018.3, it has been introduced as a new way to write code in Uniity, which is called Entity Component System (ECS). It provides a way to write performant code by default.
The ECS offers a better approach to game design that allows you to concentrate on the data and behavior that are the core problem of a game. It takes advantage of the C# Job System and Burst Compiler and allows you to take full advantage of modern chip’s multicore processors. Moving from object-oriented to data-oriented design makes it easier for you to reuse the code and easier for others to understand and work on it.
Steps to add ECS to a project:
At its core, ECS is a programming paradigm that emphasizes the use of entities, components, and systems to create and manage game objects. In traditional object-oriented programming, game objects are typically represented as objects that encapsulate both data and behavior. However, in ECS, game objects are broken down into their individual parts, with each part representing a specific aspect of the object’s behavior.
Entities are the basic building blocks of ECS. They are essentially containers for components, which represent specific attributes or properties of the entity. For example, a player character might have components for its position, velocity, health, and other properties. Components are simple data structures that store the relevant data for each property. Unlike traditional object-oriented programming, components are not responsible for any behavior or logic.
Systems, on the other hand, are responsible for processing entities and their components. Each system is designed to handle a specific aspect of the game’s behavior. For example, a physics system might be responsible for updating the positions and velocities of all entities in the game world, while an AI system might be responsible for controlling the behavior of non-player characters.
- Create a new or open an existing Unity project.
- Open the Package Manager via Windows > Package Manager.
- Open the Advanced Project Settings menu via the Gear button on the left side of the search box.
- Turn on the Enable preview packages option.
- Back to Package manager and click on the Plus (+) icon and choose Add package from the git URL.
- Add com.unity.rendering.hybrid. Then wait a bit for Unity to download and enable the package and its dependencies.