· unity unity ecs · 5 min read
[Unity ECS - Part 1] Introduction to Unity ECS & DOTS Architecture
When starting with Unity, most people begin with MonoBehaviour. However, as projects become more complex or require high performance (for example, games with many objects, large environments, or need optimization), MonoBehaviour reveals many issues. Therefore, Unity introduces ECS (Entity Component System) and DOTS (Data-Oriented Technology Stack) to solve these problems.

Series Introduction
This series will help you approach and master the ECS (Entity Component System) architecture along with DOTS (Data-Oriented Technology Stack) in Unity. Through each article, you’ll be guided step by step from foundational theory, environment setup, to building practical examples. The series aims to help you understand the differences between traditional approaches (MonoBehaviour) and the new approach with ECS, while maximizing the performance that DOTS brings to large-scale Unity projects. If you want to develop high-performance games that are easy to scale and maintain, this series is for you!
In this first article, we will explore:
- Basic concepts about Entity Component System
- Understanding how to set up a Unity Project with ECS
- Create your first HelloWorld Entity based on the concepts presented
Introduction to Entity Component System
Entity Component System (ECS) is a modern programming architecture developed by Unity to optimize performance and scalability for large game projects. Instead of organizing code in the traditional object-oriented way (OOP) with classes inheriting from MonoBehaviour, ECS divides logic into three separate parts:
- Entity: Abstract objects in the game, simply an ID, containing no data or logic.
- Component: Contains pure data only, no behavior. Each entity can have multiple different components to describe its state or properties.
- System: Contains all processing logic, performing operations on entities with appropriate components.
This approach helps maximize CPU parallel processing capabilities, optimize memory, and makes projects easy to expand and maintain. ECS is the core foundation of DOTS (Data-Oriented Technology Stack), helping Unity process a large number of objects efficiently without being limited by traditional MonoBehavior issues. We’ll dive deeper into this topic in the following articles.
Steps to Set Up ECS with a New Unity Project
You can refer to Unity’s official documentation at this address. I’ll summarize some more details below.
Step 1: Create a New Project
- Open Unity Hub
- Create a new project with Unity 6000.0.45f1 LTS or newer
- Choose “2D Core” or “3D Core” template
Follow the interface in the image below.
Step 2: Install DOTS Packages
- Open Window > Package Manager
- Switch to Unity Registry
- Install these packages:
- com.unity.entities
- com.unity.entities.graphics
- com.unity.physics
Or add these packages to the manifest.json file in the Packages directory
{
"dependencies": {
"com.unity.entities": "1.3.14",
"com.unity.entities.graphics": "1.4.12",
"com.unity.physics": "1.3.14",
"com.unity.burst": "1.8.21",
"com.unity.mathematics": "1.3.2",
"com.unity.collections": "2.5.7"
}
}
Step 3: Disable Domain Reloading in Unity
To achieve good performance with ECS, Unity recommends disabling domain reloading
To disable Domain Reloading, follow these steps:
- Open Edit > Project Settings > Editor
- Under Enter Play Mode Settings > When Entering Play Mode, select Reload Scene only
A HelloWorld ECS Example
Let’s start with a simple HelloWorld example to help you understand how ECS works. To begin, we’ll need to create a component through MonoBehaviour and the Baking process.
Define Component and Authoring MonoBehaviour
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
// File: HelloWorldAuthoring.cs
public class HelloWorldAuthoring : MonoBehaviour
{
[SerializeField] private float speed = 5f;
class Baker : Baker<HelloWorldAuthoring>
{
public override void Bake(HelloWorldAuthoring authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new HelloWorldComponent
{
Speed = authoring.speed
});
}
}
}
// Define Component
public struct HelloWorldComponent : IComponentData
{
public float Speed;
}
Baking in Unity ECS is the process of converting data from GameObject to Entity before running, helping optimize performance. As in the code above, a GameObject named HelloWorldAuthoring is created and will be converted to HelloWorldComponent through the Baking process created in the Baker class.
System Implementation
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Unity.Burst;
// File: HelloWorldSystem.cs
[BurstCompile]
public partial struct HelloWorldSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
float deltaTime = SystemAPI.Time.DeltaTime;
foreach (var (transform, helloWorld) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<HelloWorldComponent>>())
{
// Move entity along X axis
transform.ValueRW.Position.x += helloWorld.ValueRO.Speed * deltaTime;
// Reset position when too far
if (transform.ValueRO.Position.x > 10f)
{
transform.ValueRW.Position.x = -10f;
}
}
}
}
This code is a loop in Unity ECS System, used to move entities with LocalTransform and HelloWorldComponent along the X axis at a specified speed. If the X position exceeds 10, it will be reset to -10. The purpose is to illustrate how to handle movement logic for multiple entities in ECS.
Testing in SubScene
What is SubScene? Why Test in SubScene?
SubScene is a special part of the main Scene, used to contain GameObjects that are converted to Entities through Unity ECS’s baking process.
Why use SubScene when working with ECS?
- Automatic GameObject to Entity conversion: When placing a GameObject with authoring component (e.g.,
HelloWorldAuthoring
) in a SubScene, Unity will automatically bake it into an Entity when you enter Play Mode or build. - Higher performance: SubScenes can be streamed and loaded on demand, suitable for games with large worlds or multiple parts that need separate management.
- No mixing with traditional MonoBehaviour: Keeps clear separation between ECS and non-ECS parts in the project.
- Easy debugging and independent testing: Each SubScene can be tested independently without affecting the main Scene’s logic.
In summary: If you’re using Unity ECS (Entities), you should test entities, components, and systems in SubScene, as it’s the environment designed for DOTS workflow, ensuring everything is converted correctly and works as expected.
Summary
In this article, we’ve explored:
- Overview introduction of ECS (Entity Component System) architecture and DOTS in Unity, reasons to use it instead of traditional MonoBehaviour.
- Steps to create a new Unity project and install necessary packages to use ECS/DOTS.
- How to define Components, Authoring MonoBehaviour, and the Baking process to convert GameObject to Entity.
- Demonstration of building a simple System to handle movement logic for multiple entities using ECS.
- Explanation of SubScene’s role in ECS workflow and recommendation to test entities, components, and systems in SubScene to ensure effectiveness and proper DOTS workflow.
You can download the project here
Next Part
In the next part, we’ll dive deeper into ECS, DOTS and how ECS enhances system performance