# 1. DOTS Mental Model, Packages and Data Locality
Part of [[DOTS]]. Next: [[2. Jobs and Burst for GameObject Projects]].
## 1.1 Three pieces
| Concept | GameObject world | ECS world |
|---|---|---|
| Identity | GameObject | **Entity**: just an ID (index + version) |
| Data | MonoBehaviour fields | **Component**: an unmanaged `struct : IComponentData` |
| Behavior | `Update()` on each object | **System**: one `ISystem` that processes *all* matching entities |
A system doesn't ask "what does this enemy do?" It asks "for every entity with `LocalTransform` + `SwarmAgent`, do X."
## 1.2 Archetypes and chunks (why it's fast)
An **archetype** is a unique combination of component types. Every entity with the same archetype is stored in **chunks** of **16 KiB** (Entities manual, "Archetypes concepts"). Inside a chunk, each component type is a tightly packed array.
```
Chunk (archetype: LocalTransform + SwarmAgent + Health)
LocalTransform[] | p0 p1 p2 p3 ... pN
SwarmAgent[] | v0 v1 v2 v3 ... vN
Health[] | h0 h1 h2 h3 ... hN
```
When a system reads positions, the CPU streams one contiguous array. That's **Data Locality** ([[Game Programming Patterns (Review)]]): the cache prefetcher loves it. Compare 10,000 MonoBehaviours scattered across the managed heap, each `Update()` a virtual call into random memory.
## 1.3 Structural changes
Adding or removing components, or creating or destroying entities, moves an entity to another archetype or chunk. That's a **structural change**. It can't happen inside a parallel job, and on the main thread it forces jobs to complete (a **sync point**). The tools:
- **Entity Command Buffers (ECB)**: record changes in jobs, play them back later (part 4).
- **Enableable components** (`IEnableableComponent`): toggle a component on or off *without* a structural change. Ideal for "Stunned", "Dead" or "Aggro" states (the state-machine idea from [[Enemy AI State Machine]]).
## 1.4 Worlds and system groups
The default **World** runs three root groups each frame: `InitializationSystemGroup`, `SimulationSystemGroup` (your gameplay goes here by default) and `PresentationSystemGroup`. Order systems with `[UpdateInGroup]`, `[UpdateBefore]` and `[UpdateAfter]`.
## 1.5 Packages on Unity 6000.5
From Unity 6.4 on, **Entities, Entities Graphics, Collections** (and related packages such as Unity Physics) are **core packages**. They ship with the editor at **6.5.0** on 6000.5, and you can't choose a different version. To enable them:
1. **Window > Package Management > Package Manager**. Find **Entities** under the built-in/core list and make sure it's enabled. Add **Entities Graphics** if you want entities rendered.
2. **Burst** (1.8.31 on 6000.5) and **Mathematics** are dependencies that come along automatically.
3. Check **Edit > Project Settings > Player > Other Settings**: **Linear** color space, and **SRP Batcher** enabled in your URP asset (Entities Graphics requirements). For URP, set the renderer's **Rendering Path** to **Forward+**.
> [!tip] Unity 6.5 specifics
> - Enable **Preferences > Use new Hierarchy window** and the **Hierarchy** shows entity worlds, subscenes and entities.
> - The Entities **Systems** window lists every system with timing.
> - Old samples and editor tools that call `GetInstanceID()`/`InstanceID` int APIs fail to compile in Unity 6.5. Migrate them to the engine's 64-bit `EntityId`. That's the object identifier, not the ECS `Entity`.
## 1.6 Mental checklist before choosing ECS
- Do you need **thousands** of similar things (enemies, bullets, crowd, boids)?
- Is the logic **simple per entity** and the same for all?
- Can you accept **less mature tooling** for animation, UI and audio (those stay on GameObjects)?
If not, Jobs + Burst on GameObjects (part 2) may be all you need.
## Sources
- Archetypes concepts (16 KiB chunks): https://docs.unity3d.com/Packages/
[email protected]/manual/concepts-archetypes.html
- Structural changes: https://docs.unity3d.com/Packages/
[email protected]/manual/concepts-structural-changes.html
- Enableable components: https://docs.unity3d.com/Packages/
[email protected]/manual/components-enableable.html
- Entities Graphics requirements: https://docs.unity3d.com/Packages/
[email protected]/manual/index.html
- Entity world in the Hierarchy window: https://docs.unity3d.com/Packages/
[email protected]/manual/editor-hierarchy-world-node.html
- Migrate from InstanceID to EntityId: https://docs.unity3d.com/6000.5/Documentation/Manual/instanceid-to-entityid-migration.html