Chapter 12: Unity DOTS
The chapter introduction connects the existing data-oriented design to DOTS and distinguishes how SIMD and parallel processing increase throughput.
After this chapter you will be able to
- SIMD and parallel processing. Distinguish how SIMD vectorization and parallel processing perform more work simultaneously: SIMD applies one operation to multiple values on a single core, while parallel processing divides work into tasks across multiple CPU cores.
- SIMD array processing. Explain how SIMD can speed up the same operation across array values by using wide CPU registers to process multiple values at once rather than one at a time.
- Burst fit and tradeoffs. Explain why the existing array-based DOD architecture makes SIMD easier to use with Unity’s Burst compiler, and describe the costs the section identifies.
- Native arrays for Burst. Explain why the arrays used in a Burst calculation must be NativeArray<> rather than regular C# arrays, and describe the corresponding GameData change for enemy movement.
- NativeArray allocation and disposal. Describe how to allocate a native array with new NativeArray<type>() and explain why it must be disposed of manually.
- Burst-compatible enemy movement. Explain what changes in moveEnemies() for Burst and what stays the same: it gains [BurstCompile] and native-array parameters, while its movement calculation and the way Tick() calls it remain unchanged. Describe why read-only arrays use in and the modified enemyPosition array uses ref.
- Array-based work across cores. Explain why the section uses Jobs for enemy movement and how array-based data makes that work easier to divide among worker threads.
- Parallel enemy data access. Describe how the movement job marks its input arrays and why writing enemy positions requires an explicit safety assertion.
- Job execution and synchronization. Trace how the movement job is run from Tick() and what waiting for its handle does.
- Full ECS Conversion Tradeoff. Justify why the project can benefit from DOD without converting the whole game to Unity ECS, while acknowledging what ECS provides.
- Unity Systems with GameData. Trace how physics or animation can do specialized work while gameplay state remains in GameData, including how events reach Logic and how Board applies data back to Unity objects.
- Pool To Enemy Mapping. Explain why TransformAccessArray requires a pool-to-enemy lookup and a validity check, unlike the earlier approach that updates only alive enemies.
- Transform Job Data Flow. Trace how SyncEnemyTransformJob receives its data and updates each valid pooled transform.
- Per Tick Mapping Updates. Describe the order in which Board.Tick() updates pool-to-enemy mappings and runs the transform job.
- Burst and Jobs tradeoffs. Explain how Burst and Jobs can improve performance and what each costs. Burst applies the same SIMD operation to multiple values but requires Unity-specific data types; Jobs can run work across cores but require scheduling and waiting for completion.
- ECS structure and alternatives. Describe what Entity, Component, and System mean in this chapter's array-based design, and explain why ECS is not required to gain most of the cited DOD benefits.
- Selective DOTS adoption. Justify starting with data-oriented design, adding Burst and Jobs incrementally, and using TransformAccessArray only when GameObject position updates are a bottleneck.
What it builds on
- Data locality and contiguous memory - arrays of structs vs arrays of classes (chapter 2) · The relationship between contiguous data and data locality.
- Functions called by Tick() (chapter 4) · The earlier enemy-movement calculation and its EnemyPosition array
- The GameData (chapter 4) · GameData as the project’s home for gameplay data
- The Logic (chapter 4) · Static Logic functions that operate on gameplay data
- Tick() (chapter 5) · Board.Tick() as part of the board’s update work
- The Game loop implementation (chapter 5) · The Game layer connecting Unity behavior to gameplay logic
- The board (chapter 10) · The pooled enemy GameObjects and their existing updates
- Show() (chapter 5) · The Board's Show() operation
Section by section
Introduction
The chapter introduction connects the existing data-oriented design to DOTS and distinguishes how SIMD and parallel processing increase throughput.
- SIMD and parallel processing: Distinguish how SIMD vectorization and parallel processing perform more work simultaneously: SIMD applies one operation to multiple values on a single core, while parallel processing divides work into tasks across multiple CPU cores.
Why it matters: This distinction clarifies the two kinds of performance gains the chapter discusses. - Data-oriented foundation for DOTS: Explain that placing data in flat arrays helped the existing design use the L1 cache, gain performance, and reduce code complexity; state that the introduction presents DOTS as a way to seek further performance gains, with additional code complexity.
Why it matters: It places the chapter's proposed performance work in the context of the design already built.
Key terms: SIMD vectorization, parallel processing, CPU cores, data-oriented design, flat arrays, L1 cache, Unity DOTS, code complexity
12.1 Adding SIMD vectorization using the Burst compiler
Explains how SIMD processes multiple array values at once and why the book’s array-based DOD architecture makes Unity Burst useful despite its costs.
- SIMD array processing: Explain how SIMD can speed up the same operation across array values by using wide CPU registers to process multiple values at once rather than one at a time.
Why it matters: This is the performance opportunity the section introduces before applying Burst to the game data. - Burst fit and tradeoffs: Explain why the existing array-based DOD architecture makes SIMD easier to use with Unity’s Burst compiler, and describe the costs the section identifies.
Why it matters: The potential speedup has to be weighed against added complexity and reduced portability outside Unity.
Key terms: SIMD, wide registers, floats, DOD architecture, arrays, Unity DOTS, Burst compiler, server-side validation
12.1.1 GameData
This subsection changes the GameData types needed to make the enemy-movement calculation compatible with Burst.
- Native arrays for Burst: Explain why the arrays used in a Burst calculation must be NativeArray<> rather than regular C# arrays, and describe the corresponding GameData change for enemy movement.
Why it matters: This explains why changing only some of the arrays used by the movement calculation is not enough. - Burst-compatible vector type: State the vector-type change made alongside the GameData array changes for Burst compatibility.
Why it matters: The array conversion alone does not capture every type change identified for this Burst example.
Key terms: Burst compiler, NativeArray<>, GameData, managed memory, Vector2, float2
12.1.2 Allocating data
This subsection shows how to allocate NativeArray gameplay data and why it must be disposed of manually.
- NativeArray allocation and disposal: Describe how to allocate a native array with new NativeArray<type>() and explain why it must be disposed of manually.
Why it matters: Allocating native arrays also makes you responsible for releasing them.
Key terms: NativeArray<type>, garbage-collected, dispose
12.1.3 Moving enemies
This subsection adapts enemy movement to Burst-compatible native arrays, updates the related bounds check, and reports the resulting performance improvement.
- Burst-compatible enemy movement: Explain what changes in moveEnemies() for Burst and what stays the same: it gains [BurstCompile] and native-array parameters, while its movement calculation and the way Tick() calls it remain unchanged. Describe why read-only arrays use in and the modified enemyPosition array uses ref.
Why it matters: It identifies the changes needed to make this movement function Burst-compatible without changing its gameplay calculation. - Updated bounds-check math: Explain why the enemy bounds check uses math.lengthsq() instead of Vector2.sqrMagnitude when working with types such as float2.
Why it matters: The bounds check must use a math function suited to the types in the Burst-compatible code. - Burst performance comparison: Describe the reported Burst performance result and the limited conditions under which it was measured.
Why it matters: The comparison shows the benefit observed here without treating one benchmark as a universal result.
Key terms: [BurstCompile], native arrays, in, ref, enemyPosition, moveEnemies(), float2, Vector2.sqrMagnitude, math.lengthsq(), checkEnemyOutOfBounds()
12.2 Parallelizing work with Jobs
This section shows how Unity Jobs parallelizes array-based enemy movement, how the job handles reads and writes, and when scheduling overhead affects performance.
- Array-based work across cores: Explain why the section uses Jobs for enemy movement and how array-based data makes that work easier to divide among worker threads.
Why it matters: It explains why the existing array-based enemy logic is a useful candidate for Jobs. - Parallel enemy data access: Describe how the movement job marks its input arrays and why writing enemy positions requires an explicit safety assertion.
Why it matters: Parallel writes are safe only if the job's promise about distinct destination positions holds. - Job execution and synchronization: Trace how the movement job is run from Tick() and what waiting for its handle does.
Why it matters: Scheduling starts the parallel work, but waiting for completion determines when the main thread can proceed. - Batch size and job overhead: Explain how the section chooses a starting batch size and why Jobs did not outperform the Burst-only version in this test.
Why it matters: Parallel execution has costs, so a job's benefit depends on the amount and balance of work.
Key terms: Jobs, MonoBehaviours, main thread, worker threads, arrays, [ReadOnly], [NativeDisableParallelForRestriction], AliveEnemyIndices, EnemyType, EnemyVelocity
12.3 ECS and code complexity
This section explains how ECS maps to the book’s DOD architecture, why this project does not need a full ECS conversion, and how Unity systems can still work with GameData as the source of truth.
- ECS Parts in DOD: Explain how Entity, Component, and System correspond to the project’s array-based data and logic, using enemy movement as an example.
Why it matters: This mapping lets you compare Unity’s ECS terms with the architecture the project already uses. - Full ECS Conversion Tradeoff: Justify why the project can benefit from DOD without converting the whole game to Unity ECS, while acknowledging what ECS provides.
Why it matters: It helps you decide whether adopting ECS solves a problem your existing data layout has not already addressed. - Unity Systems with GameData: Trace how physics or animation can do specialized work while gameplay state remains in GameData, including how events reach Logic and how Board applies data back to Unity objects.
Why it matters: You can retain useful Unity features without scattering authoritative gameplay state outside the DOD architecture.
Key terms: Entity Component System, ECS, Entity, Component, System, EnemyPosition, GameData, Logic, Components, Systems
12.4 Parallelizing GameObject transform access with TransformAccessArray
This section adapts a pooled-enemy Board to update GameObject transforms in parallel with TransformAccessArray, while managing pool mappings and their lifecycle.
- Pool To Enemy Mapping: Explain why TransformAccessArray requires a pool-to-enemy lookup and a validity check, unlike the earlier approach that updates only alive enemies.
Why it matters: The reverse lookup makes it possible to find the right enemy position while iterating over every pooled transform. - Transform Pool Preparation: Describe how newly instantiated enemies and enemies restored by Show() are prepared for parallel transform updates.
Why it matters: The job can update an enemy only if its transform and pool mapping were set up when the object was created or restored. - Transform Array Lifecycle: Distinguish resetting transform and mapping entries when gameplay ends from disposing of their allocated arrays when Board is destroyed.
Why it matters: Resetting entries preserves correct indices across games without discarding reusable allocations. - Transform Job Data Flow: Trace how SyncEnemyTransformJob receives its data and updates each valid pooled transform.
Why it matters: This is how the job connects pooled GameObjects to gameplay positions without accessing Board fields directly. - Per Tick Mapping Updates: Describe the order in which Board.Tick() updates pool-to-enemy mappings and runs the transform job.
Why it matters: Updating the mappings first gives the job an accurate view of which pooled transforms are active this tick. - Parallelization Performance Limits: Explain why parallel transform updates give little benefit in the simple example but could help with more objects.
Why it matters: Parallelizing a task does not substantially speed up a game unless that task matters to its current performance.
Key terms: TransformAccessArray, AliveEnemyIndices, m_enemyToPoolIndex, m_poolToEnemyIndex, SpriteParent, Show(), pool objects, Hide(), m_enemyTransforms, OnDestroy()
12.5 Conclusion
The chapter conclusion weighs the performance benefits of Unity DOTS against its code complexity and argues for adding tools selectively to a data-oriented design.
- Burst and Jobs tradeoffs: Explain how Burst and Jobs can improve performance and what each costs. Burst applies the same SIMD operation to multiple values but requires Unity-specific data types; Jobs can run work across cores but require scheduling and waiting for completion.
Why it matters: A speedup is useful only when its constraints and overhead fit the work being done. - ECS structure and alternatives: Describe what Entity, Component, and System mean in this chapter's array-based design, and explain why ECS is not required to gain most of the cited DOD benefits.
Why it matters: The reader can distinguish the benefits of array-based DOD from the additional structure and complexity of ECS. - Selective DOTS adoption: Justify starting with data-oriented design, adding Burst and Jobs incrementally, and using TransformAccessArray only when GameObject position updates are a bottleneck.
Why it matters: Selective adoption preserves clarity and maintainability while targeting actual performance limits.
Key terms: Burst, SIMD instructions, Jobs, parallel processing, ECS, Entity, Component, System, data-oriented design, TransformAccessArray
12.6 Summary
This section summarizes how Burst, Jobs, ECS, and TransformAccessArray affect performance and complexity in Unity DOTS.
Concepts explained in this chapter
- TransformAccessArrayA Unity data structure that provides job-compatible access to GameObject transforms.
- entity component systemECS is an architecture that represents entities separately from their data components and the systems that process those components.
- JobsUnity's job-system mechanism for scheduling work that can execute asynchronously or in parallel.
- data-oriented programmingAn approach to structuring software around the flow and transformation of data rather than relationships between objects.
- BurstUnity's optimizing compiler that converts compatible C# code into highly optimized native code.
- complexity metricA measure of the structural intricacy and difficulty of understanding, modifying, or executing software code.
- Unity DOTSUnity's Data-Oriented Technology Stack, a collection of packages for building data-oriented applications and games.
- parallelismExecuting computational work concurrently by dividing it into tasks.
- componentAn ECS data unit that stores an attribute or group of attributes associated with an entity.
- entityIn this section's ECS representation, an entity is an index in data arrays that identifies an individual record.
- systemIn this section's ECS representation, a system is logic that operates on data arrays.
- data typeA specification of the kind of value a program element can represent and the operations and storage interpretation associated with it.
- branchControl flow that selects among different execution paths, commonly according to conditions.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
