This article explains you about the Unity ECS (Entity component System) and why to use Unity ECS.
Introduction to Unity ECS
The New Implementation of Entity Component system is a design pattern mostly used in game development consisting of entities, components and system.
Entity – a collection of components which are usually implemented as objects consisting unique ID.
Component – A container of data only.
System – defines the game behavior and contains logic.
Unity framework is shifting from the old entity component system to more modern data oriented entity component system which will make code reuse easier. ECS leverages the C# Job system and Burst compiler which allows you to take the full advantage of today’s multi core processors.
There are different frameworks used for ECS like:
- Entitas (C#)
- Artemis (C#)
- EgoCS (C#)
- EntityX (C++)
- Anax (C++)
Why Unity ECS?
Unity ECS is an interesting approach not only to design your game code but also many other features that make up the unity engine from physics simulation to graphics rendering.
There are two forms of Unity that defines different approaches with mono Behavior:
- Pure ECS
- Hybrid ECS
In Pure ECS, the entities are the new Game Objects and there are no more mono Behaviors i.e., data is stored in components and Logic in systems. It also utilizes the new C# job system which gives performance benefits with the help of Burst Compiler and Multithreading.
In Hybrid ECS, it includes all the features of Pure ECS and also includes special helper classes which convert Game Objects into entities and mono behaviors into components.
Unity ECS makes the performance much better through efficient machine code for all platforms, which includes the following key features:
Optimized Data – whenever the code is written using pure unity ECS, your component data is guaranteed to be stored linearly in memory. Your system will access entity components in the most optimal possible ways.
Multithreaded code –utilizes C# job system, which allows you to write multithreaded code in safe and simple way. This allows you to run the systems in parallel and utilizes cores in the processor.
Burst Compiler – This compiler is a new LLVM (Low Level Virtual Machine) based math – aware backend compiler technology which takes C# jobs and produces highly-optimized code taking advantage of the particular capabilities of the platform you’re compiling for. This compiler is so powerful that it renders so many instances (e.g. 24K Instances) of the same model.
Example: Render Massive number of skinned meshes in Unity for10K instances at an average 185 fps i.e., more than 850 triangles per second.
So, this is just an introduction part of Unity ECS. Stay Tuned for more advanced post on similar topic.