5.1K Views
November 16, 26
スライド概要
リアルタイム3Dコンテンツを制作・運用するための世界的にリードするプラットフォームである「Unity」の日本国内における販売、サポート、コミュニティ活動、研究開発、教育支援を行っています。ゲーム開発者からアーティスト、建築家、自動車デザイナー、映画製作者など、さまざまなクリエイターがUnityを使い想像力を発揮しています。
ROADMAP Safe Harbor Statement The following is intended for informational purposes only, and may not be incorporated into any contract. No purchasing decisions should be made based on the following materials. Unity is not committing to deliver any functionality, features or code. The development, timing and release of all products, functionality and features are at the sole discretion of Unity, and are subject to change. Nyhavn at sunset Source: Moahim, Creative Commons Attribution-Share Alike 4.0 International
Joe Valenzuela Christopher Redden Senior Director, Core Engine Principal Software Engineer
→ ECS for All → Phase 1 ⎯ Data-Oriented Design DOD ⎯ DOD at Unity ⎯ “DOTSˮ and Entities Phase 2 ⎯ TKTK
Data Oriented Design
Data Oriented Design Unite/Tokyo Background Performance relative to 1980 (log scale) 10K +20%/yr CPU 1K 100 10 +52%/yr +25%/yr DRAM +7%/yr 1 1980 1985 1990 1995 2000 2005 2010 Source: J. L. Hennessy and D. A. Patterson, Computer Architecture: A Quantitative Approach, 5th ed., Morgan Kaufmann, 2012 “50 Years of Microprocessor Trend Data” by Karl Rupp, licensed under CC BY 4.0 Source: github.com/karlrupp/microprocessor-trend-data
Data Oriented Design Unite/Tokyo Designing data CORE CORE CORE CORE Common program operations Source: 6it.dev, “Infographics: Operation Costs in CPU Clock Cycles”, https://6it.dev/blog/infographics-operation-costs-in-cpu-clock-cycles-741, September 12, 2016
Data Oriented Design Unite/Tokyo Designing data free CORE CORE CORE CORE Control unit Control unit Control unit Control unit ALU ALU ALU ALU Registers Registers Registers Registers 32 kb (1 ns) Instruction 256kb (3-4 ns) Level 2 cache 16 mb (10-23 ns) 32 GB (~60 ns) data Instruction data Instruction Level 2 cache data Level 2 cache Level 3 shared cache Memory Instruction data Level 2 cache
Data Oriented Design Unite/Tokyo Designing data // x0, y0, z0, x1, y1, z1, ... float[] positions = new float[3 * count]; // scale Y for (int i = 0; i < count; ++i) positions[i * 3 + 1] *= 0.5f; positions 0x00 (x0) 0x04 (y0) 0x08 (z0) 0x0C (x1) 0x10 (y1) 0x14 (z1) 0x18 (x2) 0x1C (y2) 0x20 (z2) 0x24 (x3) 0x28 (y3) 0x2C (z3)
Unite/Tokyo Data Oriented Design Starting with data Ideal solution Input Transform Output
Unite/Tokyo Data Oriented Design Starting with data ⚠ Ideal solution Input Transform Output x0 y0 z0 w0 x0 x1 x2 x3 x1 y1 z1 w1 y0 y1 y2 y3 x2 y2 z2 w2 z0 z1 z2 z3 x3 y3 z3 w3
Unite/Tokyo Data Oriented Design Starting with data Ideal solution Input OOP Solution Input Transform Output Output
Unite/Tokyo Data Oriented Design Starting with data Ideal solution Input OOP Solution Input Transform Output Output
Unite/Tokyo Data Oriented Design Starting with data Ideal solution Input Transform Output Or is it?
Unite/Tokyo
Data Oriented Design
Designing data
●
How many instances?
int test_intersection(Sphere s, Plane p)
{
const float num = fabsf(p.x * s.xc + p.y * s.yc + p.z * s.zc);
const float den = sqrtf(p.x * p.x + p.y * p.y + p.z * p.z );
const float dis = num / den;
return dis <= s.radius ? -1 : 1;
}
void test_intersections(int* dest, const Sphere* s,
int num_spheres, Plane p)
{
const float den = sqrtf(p.x * p.x + p.y * p.y + p.z * p.z);
for (int i=0; i<num_spheres; ++i)
{
const float num = fabsf(p.x * s.xc + p.y * s.yc + p.z * s.zc);
const float dis = num / den;
dest[i] = dis <= s->radius ? -1 : 1;
}
}
Unite/Tokyo
Data Oriented Design
Designing data
●
How many instances?
int test_intersection(Sphere s, Plane p)
{
const float num = fabsf(p.x * s.xc + p.y * s.yc + p.z * s.zc);
const float den = sqrtf(p.x * p.x + p.y * p.y + p.z * p.z );
const float dis = num / den;
return dis <= s.radius ? -1 : 1;
}
void test_intersections(int* dest, const Sphere* s,
int num_spheres, Plane p)
{
const float den = sqrtf(p.x * p.x + p.y * p.y + p.z * p.z);
for (int i=0; i<num_spheres; ++i)
{
const float num = fabsf(p.x * s.xc + p.y * s.yc + p.z * s.zc);
const float dis = num / den;
dest[i] = dis <= s->radius ? -1 : 1;
}
}
Unite/Tokyo Data Oriented Design Designing data ● What changes and what doesnʼt? struct enemy { char name[32]; int enemy_type; CollisionTris collision; int last_visible; matrix4x4 po; float health; }
Unite/Tokyo Data Oriented Design Designing data ● What changes and what doesnʼt? struct enemy { char name[32]; int enemy_type; CollisionTris collision; int last_visible; matrix4x4 po; float health; }
Unite/Tokyo Data Oriented Design Designing data ● How and how often is your data used? struct marker { matrix4x4 po ; float health; char team_alignment[8]; char* name ; };
Unite/Tokyo Data Oriented Design Designing data ● How and how often is your data used? struct marker { matrix4x4 po ; float health; char team_alignment[8]; char* name ; };
Unite/Tokyo Data Oriented Design Designing data ● How and how often is your data used? struct marker { matrix4x4 po ; float health; char team_alignment[8]; char* name ; };
Unite/Tokyo Data Oriented Design Designing data ● What can be shared? “Mushroom Warrior” struct enemy { char* name; enemy_class * klass; int last_visible ; matrix4x4 po; float health; } struct enemy_class { int type; CollisionTris collision; }
Unite/Tokyo Data Oriented Design Designing data ● Whatʼs the range and distribution? struct foo { int bar; }; // ? ? ? ? ? ?
Unite/Tokyo Data Oriented Design Designing data ● Whatʼs the range and distribution? struct foo { int bar; }; // { 100, 102, 101, 104, 103, 105, 104 } 100 102 101 104 103 105 104 BASE VAL DELTA DELTA DELTA DELTA DELTA DELTA 100 +2 -1 +3 -1 +2 -1
Unite/Tokyo Data Oriented Design Designing data ● How much accuracy? p(x)= 0.99999999999565793 − 0.49999999798761679 * x + 0.04166652049177614 x^2 − 0.0013854855078607044 x^3
Unite/Tokyo Data Oriented Design Designing data ● How much accuracy? p(x)= 0.99999999999565793 − 0.49999999798761679 * x + 0.04166652049177614 x^2 − 0.0013854855078607044 x^3
Unite/Tokyo Data Oriented Design Designing data ● How complex is your data? Batch #0 Batch #1
Unite/Tokyo Data Oriented Design Designing data ● How complex is your data? Batch #0 Batch #1
DOTS milestones DOTS The past pre-DOTS Nov 2017 - Nov 2020 Early DOTS Present Fall 2020 - Nov 2026 Entities ECS For All
GameObjects
GameObject
GameObject
Transform
Transform
RigidBody
MeshRenderer
Speed
public class Speed : MonoBehaviour {
public float m_Speed;
public float m_Time;
void Update() {
if (m_Speed > 88.0f)
m_Time -= 30.0f;
}
}
MeshRenderer
GameObjects
GameObject
GameObject
Transform
Transform
RigidBody
MeshRenderer
Speed
public class Speed : MonoBehaviour {
public float m_Speed;
public float m_Time;
void Update() {
if (m_Speed > 88.0f)
m_Time -= 30.0f;
}
}
MeshRenderer
DOTS Unite/Tokyo DOTS features and packages Gameplay Physics Rendering [...] Entities Graphics, Netcode for Entities, Unity Physics Entity Component System ECS Architectural Pattern Entities Package Scheduling C# Job System Compilation Burst Compiler Galaxy Game DOTS Samples ECS Character + Vehicle Controller Packages
Unite/Tokyo DOTS ECS Archetypes/Chunks Archetype 0 Archetype #0 Chunk #2 Entity #11 Health Archetype 1 Chunk 0 Chunk 0 Chunk 1 Chunk 1 Chunk 2 Chunk 2 Navigation
DOTS Unite/Tokyo ECS gameplay architecture - IComponentData public struct Movement : IComponentData { public float3 Direction; public float Speed; }
Unite/Tokyo
DOTS
ECS Systems
Archetype 0
public partial struct HealthSystem : ISystem {
public void OnUpdate(ref SystemState state)
{
// Iterate over all entities with a
// mutable Health component
foreach (var (health, entity) in
SystemAPI.Query<RefRW<Health>>()
.WithEntityAccess())
{
// ...
}
}
}
Archetype 1
Chunk 0
Chunk 0
Chunk 1
Chunk 1
Chunk 2
Chunk 2
Unite/Tokyo DOTS ECS Queries Archetype 0 Archetype 1 Chunk 0 Chunk 0 Chunk 1 Chunk 1 Chunk 2 Chunk 2 With orange, without blue Query X
Unite/Tokyo DOTS Entities 1.0 Results based on testing performed on a laptop with a high-end Intel CPU and NVIDIA GPU, Unity 2022.3, Entities 1.2.0-pre.6. Results may vary.
Unite/Tokyo DOTS Learning ECS be like ⚠ State of things as of Entities 1.x ● Requires installing DOTS and ECS packages ● Requires using a separate Hierarchy window ● There are confusing blinking yellow dots everywhere ● Requires SubScenes to do almost everything ● Canʼt bind between things from main scene to SubScene ● Must use Baking ● Requires intermediate ‘authoringʼ type ● Canʼt use Timeline ● Many built-in types donʼt Bake (not obvious) ● Must use Entities SceneManager ● Player builds use StreamingAssets ● Cannot use addressables ● Asset duplication between Entity Scenes & GameObject Scenes ● Cannot progressively migrate scene content to Entities ● Working between Entities & GameObjects together very difficult ● Many things fail because of all the jank: WebGL, Lights Baking, Fog, etc
Phase II Where are we, and where are we going
Unite/Tokyo Where are we Where we are The past Nov 2017 Nov 2020 Fall 2020 Nov 2026 Present pre-DOTS Early DOTS Entities ECS For All We are here
Unite/Tokyo Where are we What still holds people back Setup Authoring Content Interop • Separate DOTS and ECS packages • A separate Hierarchy window • SubScenes for anything basic • Baking and intermediate ‘authoringʼ types • Many built-in types donʼt bake • No Timeline • Entities SceneManager • StreamingAssets in player builds • No Addressables • Assets duplicated across scene types • No progressive migration • Entities and GameObjects together is hard • WebGL, Lights Baking, Fog break
Unite/Tokyo Where are we Today: a canyon ECS GameObjects Limited, but powerful The full utility of Unity Baking, SubScenes • Burst Compiler • C# Job System • Entities Graphics, Netcode for Entities, Unity Physics • Designed for performance at scale • Every built-in component • Timeline • Addressables • Lights Baking, Fog, WebGL
The original plan ECS was always meant to be the new foundation for the rest of Unity. But the path there had become unclear.
Unite/Tokyo A challenge Where are we
Unite/Tokyo Where are we A challenge “I would believe in this if an Entity and a GameObject could share a Transform system.ˮ
He knew this was in fact very complicated. He was trying to making a point about how far away we were.
He knew this was in fact very complicated. He was trying to making a point about how far away we were. But we took a moment to think about it...
He knew this was in fact very complicated. He was trying to making a point about how far away we were. But we took a moment to think about it... “Actually, why not?ˮ
Instead of bringing the rest of Unity to ECS, we will bring ECS to the rest of Unity. The rest of Unity ECS ECS The rest of Unity
How?
What is a GameObject? Under the hood)
Unite/Tokyo ECS for All What a GameObject really is C# GameObject Thin wrapper (a pointer) C GameObject The real object and its memory
Unite/Tokyo ECS for All What a GameObject really is C# GameObject Thin wrapper (a pointer) GameObject The real object and its memory C GameObject
Unite/Tokyo ECS for All What a GameObject really is C# GameObject GameObject GameObject Transform, Light, Rigidbody… Built-in components Thin wrapper (a pointer) C The real object and its memory
Unite/Tokyo ECS for All What a GameObject really is C# GameObject Built-in components Thin wrapper (a pointer) C GameObject GameObject Transform, Light, Rigidbody Transform, Light, Rigidbody… The real object and its memory
Unite/Tokyo ECS for All What a GameObject really is C# GameObject Built-in components MonoBehaviour Thin wrapper (a pointer) C GameObject GameObject Transform, Light, Rigidbody Transform, Light, Rigidbody… MonoBehaviour The real object and its memory
Unite/Tokyo ECS for All What a GameObject really is C# GameObject Built-in components MonoBehaviour Thin wrapper (a pointer) C GameObject GameObject Transform, Light, Rigidbody Transform, Light, Rigidbody… MonoBehaviour The real object and its memory MonoBehaviour
Unite/Tokyo ECS for All Where a GameObjectʼs components live C# managed objects C native memory MonoBehaviour Transform Transform wrapper Light Light wrapper Rigidbody Garbage-collected heap Native allocations
Unite/Tokyo ECS for All Where a GameObjectʼs components live What if we added ECS components to that? C# managed objects C native memory MonoBehaviour Transform Transform wrapper Light Light wrapper Rigidbody ECS chunks struct Movement : IComponentData { float3 Direction; float Speed; } Chunk 0 Movement Garbage-collected heap Native allocations Chunk-based IComponentData
What is a Unity Object?
Unite/Tokyo ECS for All What is a Unity Object? UnityObject UnityObject GameObject Component Light Arrows point to the base class. Inheritance simplified.
Unite/Tokyo ECS for All What is a Unity Object? UnityObject class Object { int32 InstanceID; } InstanceID maps to an Object*, so any Object can be found from its InstanceID. Used all over the engine.
Unite/Tokyo ECS for All What is a Unity Object? UnityObject class Object { int32 InstanceID; } InstanceID maps to an Object*, so any Object can be found from its InstanceID. Used all over the engine. A unique 32-bit integer for every Object.
Unite/Tokyo ECS for All What is a Unity Object? UnityObject class Object { int32 InstanceID; } InstanceID maps to an Object*, so any Object can be found from its InstanceID. Used all over the engine. A unique 32-bit integer for every Object. Allocated with a simple bump allocator. next 1 2 3 4 5
Unite/Tokyo ECS for All What is a Unity Object? UnityObject class Object { int32 InstanceID; } InstanceID maps to an Object*, so any Object can be found from its InstanceID. Used all over the engine. A unique 32-bit integer for every Object. Allocated with a simple bump allocator. Only valid at runtime. next 1 2 3 4 5
What is an Entity?
Unite/Tokyo ECS for All What is an Entity? Entity struct Entity { int Index; int Version; } Entity maps to a Chunk* and IndexInChunk, so any entityʼs components can be found from its Entity.
Unite/Tokyo ECS for All What is an Entity? Entity struct Entity { int Index; int Version; } Entity maps to a Chunk* and IndexInChunk, so any entityʼs components can be found from its Entity. A unique versioned handle.
Unite/Tokyo ECS for All What is an Entity? Entity struct Entity { int Index; int Version; } Entity maps to a Chunk* and IndexInChunk, so any entityʼs components can be found from its Entity. A unique versioned handle. Allocated with a thread-safe block store.
Unite/Tokyo ECS for All What is an Entity? Entity struct Entity { int Index; int Version; } Entity maps to a Chunk* and IndexInChunk, so any entityʼs components can be found from its Entity. A unique versioned handle. Allocated with a thread-safe block store. Only valid at runtime.
Unite/Tokyo ECS for All What is an Entity? Entity struct Entity { int Index; int Version; } A unique versioned handle. Allocated with a thread-safe block store. Only valid at runtime. Entity maps to a Chunk* and IndexInChunk, so any entityʼs components can be found from its Entity. Curious how Index and Version work? The source is public in the Entities package. Weʼll skip explaining it today.
Unite/Tokyo ECS for All InstanceID vs Entity InstanceID Entity int32 InstanceID; struct Entity { int Index; int Version; }
Unite/Tokyo ECS for All InstanceID vs Entity InstanceID Entity int32 InstanceID; struct Entity { int Index; int Version; } ● Bump allocator
Unite/Tokyo ECS for All InstanceID vs Entity InstanceID Entity int32 InstanceID; struct Entity { int Index; int Version; } ● Bump allocator ● Index / Version handle
Unite/Tokyo ECS for All InstanceID vs Entity InstanceID Entity int32 InstanceID; struct Entity { int Index; int Version; } ● Bump allocator ● 4 bytes ● Index / Version handle
Unite/Tokyo ECS for All InstanceID vs Entity InstanceID Entity int32 InstanceID; struct Entity { int Index; int Version; } ● Bump allocator ● Index / Version handle ● 4 bytes ● 8 bytes
Unite/Tokyo ECS for All InstanceID vs Entity InstanceID Entity int32 InstanceID; struct Entity { int Index; int Version; } ● Bump allocator ● Index / Version handle ● 4 bytes ● 8 bytes ● Only valid at runtime
Unite/Tokyo ECS for All InstanceID vs Entity InstanceID Entity int32 InstanceID; struct Entity { int Index; int Version; } ● Bump allocator ● Index / Version handle ● 4 bytes ● 8 bytes ● Only valid at runtime ● Only valid at runtime
Unite/Tokyo ECS for All InstanceID vs Entity InstanceID Entity int32 InstanceID; struct Entity { int Index; int Version; } ● Bump allocator ● Index / Version handle ● 4 bytes ● 8 bytes ● Only valid at runtime ● Only valid at runtime ● Uniquely identifies an Object
Unite/Tokyo ECS for All InstanceID vs Entity InstanceID Entity int32 InstanceID; struct Entity { int Index; int Version; } ● Bump allocator ● Index / Version handle ● 4 bytes ● 8 bytes ● Only valid at runtime ● Only valid at runtime ● Uniquely identifies an Object ● Uniquely identifies an Entity
What if we replaced InstanceID with Entity?
Unite/Tokyo ECS for All What if we replaced InstanceID with Entity? UnityObject class Object { int32 InstanceID; }
Unite/Tokyo ECS for All What if we replaced InstanceID with Entity? UnityObject class Object { int32 InstanceID; Entity EntityId; }
Unite/Tokyo ECS for All What if we replaced InstanceID with Entity? UnityObject class Object { int32 InstanceID; Entity EntityId; } Entities and GameObjects share the same Id system.
Unite/Tokyo ECS for All What if we replaced InstanceID with Entity? UnityObject class Object { int32 InstanceID; Entity EntityId; } Entity and GameObject share the same Id system. A GameObject is implicitly an Entity. Yes, that also includes all UnityObjects, so only GameObjects will get valid ECS Chunks.
Unite/Tokyo ECS for All What if we replaced InstanceID with Entity? UnityObject class Object { int32 InstanceID; Entity EntityId; } Entity and GameObject share the same Id system. A GameObject is implicitly an Entity. Yes, that also includes all UnityObjects, so only GameObjects will get valid ECS Chunks. An Entity maps to both an Object* and Chunk* + IndexInChunk.
What if we replaced InstanceIDs with Entity? Do we get ECS on GameObjects for free?
What if we replaced InstanceIDs with Entity? Do we get ECS on GameObjects for free? Ye…
What if we replaced InstanceIDs with Entity? Do we get ECS on GameObjects for free? Ye…no.
What if we replaced InstanceIDs with Entity? Do we get ECS on GameObjects for free? Ye…no. But it becomes possible! → So letʼs do it.
Unite/Tokyo ECS for All If youʼve followed 6.0 6.7, youʼve felt some of this 1 2 3 4 The type became opaque InstanceID became 8 bytes Renamed to EntityId The bump allocator replaced by the ECS Entity allocator int32 ↓ struct InstanceID { int32 value; } struct InstanceID { int32 value; } ↓ struct InstanceID { int64 value; } So nobody could treat the value as a number and do… weird stuff struct InstanceID { int64 value; } ↓ struct EntityId { int64 value; } struct EntityId { int64 value; } ↓ struct EntityId { int Index; int Version; }
So now, in 6.7, a GameObject and an Entity are addressed with the same EntityId. A GameObject is, at its core, an Entity! GameObject EntityId Entity
ECS For All 7.X
Unite/Tokyo Whatʼs in 7.0 ECS For All
Unite/Tokyo ECS For All Whatʼs in 7.0 ● Entities core functionality is built in The package still exists for optional features: Baking, SubScenes and source-gen APIs IJobEntity, idiomatic foreach, …)
Unite/Tokyo ECS For All Whatʼs in 7.0 ● Entities core functionality is built in The package still exists for optional features: Baking, SubScenes and source-gen APIs IJobEntity, idiomatic foreach, …) ● IComponentData and DynamicBuffer on GameObjects
Unite/Tokyo ECS For All Whatʼs in 7.0 ● Entities core functionality is built in The package still exists for optional features: Baking, SubScenes and source-gen APIs IJobEntity, idiomatic foreach, …) ● IComponentData and DynamicBuffer on GameObjects ● Editor support: Inspector, Prefabs, Copy + Paste, Undo
Unite/Tokyo ECS For All Whatʼs in 7.0 ● Entities core functionality is built in The package still exists for optional features: Baking, SubScenes and source-gen APIs IJobEntity, idiomatic foreach, …) ● IComponentData and DynamicBuffer on GameObjects ● Editor support: Inspector, Prefabs, Copy + Paste, Undo ● Scene serialisation and build support
Unite/Tokyo ECS For All Whatʼs in 7.0 ● Entities core functionality is built in The package still exists for optional features: Baking, SubScenes and source-gen APIs IJobEntity, idiomatic foreach, …) ● IComponentData and DynamicBuffer on GameObjects ● Editor support: Inspector, Prefabs, Copy + Paste, Undo ● Scene serialisation and build support ● Unified lifecycles Destroying the GameObject destroys its ECS data; destroying the Entity destroys the GameObject
Unite/Tokyo
ECS For All
Example: moving ships
public class Ship : MonoBehaviour
{
public float3 Velocity;
[SerializeField] ShipLoadout loadout;
[SerializeField] Faction faction;
HealthPool hull;
WeaponBank weapons;
void Start() => (hull, weapons) = loadout.Build(this);
void Update()
{
UpdateTargeting(faction.Enemies);
weapons.Tick(Time.deltaTime);
if (hull.IsCritical) EmitDistressSignal();
RegenerateShields();
transform.position +=
(Vector3)(Velocity * Time.deltaTime);
}
void OnCollisionEnter(Collision c) => hull.ApplyImpact(c);
void OnDockRequested(Station s) { /* ... */ }
// ... 400 more lines of gameplay
}
One ship: fine.
Unite/Tokyo
ECS For All
Example: moving ships
public class Ship : MonoBehaviour
{
public float3 Velocity;
[SerializeField] ShipLoadout loadout;
[SerializeField] Faction faction;
HealthPool hull;
WeaponBank weapons;
void Start() => (hull, weapons) = loadout.Build(this);
void Update()
{
UpdateTargeting(faction.Enemies);
weapons.Tick(Time.deltaTime);
if (hull.IsCritical) EmitDistressSignal();
RegenerateShields();
transform.position +=
(Vector3)(Velocity * Time.deltaTime);
}
void OnCollisionEnter(Collision c) => hull.ApplyImpact(c);
void OnDockRequested(Station s) { /* ... */ }
// ... 400 more lines of gameplay
}
One ship: fine.
10,000 ships:
• 10,000 Update() calls every frame
• Each one a call from C into C#
• Each Transform moved one at a time
Can be too slow. But donʼt rewrite the Ship:
move just the hot part to ECS.
Unite/Tokyo
ECS For All
Migrate just the velocity
The MonoBehaviour hands velocity to ECS
public struct Velocity : IComponentData { public float3 Value; }
public class Ship : MonoBehaviour
{
public float3 StartVelocity;
[SerializeField] ShipLoadout loadout;
[SerializeField] Faction faction;
HealthPool hull;
WeaponBank weapons;
void Start()
{
(hull, weapons) = loadout.Build(this);
AddComponentData(this.gameObject,
new Velocity { Value = StartVelocity });
}
void Update()
{
UpdateTargeting(faction.Enemies);
weapons.Tick(Time.deltaTime);
if (hull.IsCritical) EmitDistressSignal();
RegenerateShields();
transform.position +=
(Vector3)(Velocity * Time.deltaTime);
}
void OnCollisionEnter(Collision c) => hull.ApplyImpact(c);
// ... 400 more lines of gameplay
}
The gameplay code stays in the MonoBehaviour. Only
the movement leaves Update(): the Ship hands its
velocity to ECS once.
Unite/Tokyo
ECS For All
Migrate just the velocity
The MonoBehaviour hands velocity to ECS
public struct Velocity : IComponentData { public float3 Value; }
public class Ship : MonoBehaviour
{
public float3 StartVelocity;
[SerializeField] ShipLoadout loadout;
[SerializeField] Faction faction;
HealthPool hull;
WeaponBank weapons;
void Start()
{
(hull, weapons) = loadout.Build(this);
AddComponentData(this.gameObject,
new Velocity { Value = StartVelocity });
}
void Update()
{
UpdateTargeting(faction.Enemies);
weapons.Tick(Time.deltaTime);
if (hull.IsCritical) EmitDistressSignal();
RegenerateShields();
}
void OnCollisionEnter(Collision c) => hull.ApplyImpact(c);
// ... 400 more lines of gameplay
}
A system moves every ship
partial struct MoveSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
}
}
Unite/Tokyo
ECS For All
Migrate just the velocity
The MonoBehaviour hands velocity to ECS
public struct Velocity : IComponentData { public float3 Value; }
public class Ship : MonoBehaviour
{
public float3 StartVelocity;
[SerializeField] ShipLoadout loadout;
[SerializeField] Faction faction;
HealthPool hull;
WeaponBank weapons;
void Start()
{
(hull, weapons) = loadout.Build(this);
AddComponentData(this.gameObject,
new Velocity { Value = StartVelocity });
}
void Update()
{
UpdateTargeting(faction.Enemies);
weapons.Tick(Time.deltaTime);
if (hull.IsCritical) EmitDistressSignal();
RegenerateShields();
}
void OnCollisionEnter(Collision c) => hull.ApplyImpact(c);
// ... 400 more lines of gameplay
}
A system moves every ship
partial struct MoveSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
foreach (var (transform, velocity) in
SystemAPI.Query<TransformRef, RefRO<Velocity>>())
{
}
}
}
Unite/Tokyo
ECS For All
Migrate just the velocity
The MonoBehaviour hands velocity to ECS
public struct Velocity : IComponentData { public float3 Value; }
public class Ship : MonoBehaviour
{
public float3 StartVelocity;
[SerializeField] ShipLoadout loadout;
[SerializeField] Faction faction;
HealthPool hull;
WeaponBank weapons;
void Start()
{
(hull, weapons) = loadout.Build(this);
AddComponentData(this.gameObject,
new Velocity { Value = StartVelocity });
}
void Update()
{
UpdateTargeting(faction.Enemies);
weapons.Tick(Time.deltaTime);
if (hull.IsCritical) EmitDistressSignal();
RegenerateShields();
}
void OnCollisionEnter(Collision c) => hull.ApplyImpact(c);
// ... 400 more lines of gameplay
}
A system moves every ship
partial struct MoveSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
foreach (var (transform, velocity) in
SystemAPI.Query<TransformRef, RefRO<Velocity>>())
{
transform.Position +=
velocity.ValueRO.Value *
SystemAPI.Time.DeltaTime;
}
}
}
Unite/Tokyo
ECS For All
Migrate just the velocity
The MonoBehaviour hands velocity to ECS
public struct Velocity : IComponentData { public float3 Value; }
public class Ship : MonoBehaviour
{
public float3 StartVelocity;
[SerializeField] ShipLoadout loadout;
[SerializeField] Faction faction;
HealthPool hull;
WeaponBank weapons;
void Start()
{
(hull, weapons) = loadout.Build(this);
AddComponentData(this.gameObject,
new Velocity { Value = StartVelocity });
}
void Update()
{
UpdateTargeting(faction.Enemies);
weapons.Tick(Time.deltaTime);
if (hull.IsCritical) EmitDistressSignal();
RegenerateShields();
}
void OnCollisionEnter(Collision c) => hull.ApplyImpact(c);
// ... 400 more lines of gameplay
}
A Burst system moves every ship
[BurstCompile]
partial struct MoveSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
foreach (var (transform, velocity) in
SystemAPI.Query<TransformRef, RefRO<Velocity>>())
{
transform.Position +=
velocity.ValueRO.Value *
SystemAPI.Time.DeltaTime;
}
}
}
Main thread, Burst-compiled, one system for every ship.
Gameplay stays in the MonoBehaviour.
Unite/Tokyo
ECS For All
Go wide with IJobEntity
The system from before
[BurstCompile]
partial struct MoveSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
foreach (var (transform, velocity) in
SystemAPI.Query<TransformRef, RefRO<Velocity>>())
{
transform.Position +=
velocity.ValueRO.Value *
SystemAPI.Time.DeltaTime;
}
}
}
The same loop as an IJobEntity
[BurstCompile]
partial struct MoveJob : IJobEntity
{
public float DeltaTime;
void Execute(TransformRef transform, in Velocity velocity)
{
transform.Position += velocity.Value * DeltaTime;
}
}
Unite/Tokyo
ECS For All
Go wide with IJobEntity
The system schedules the job
[BurstCompile]
partial struct MoveSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
foreach (var (transform, velocity) in
SystemAPI.Query<TransformRef, RefRO<Velocity>>())
{
transform.Position +=
velocity.ValueRO.Value *
SystemAPI.Time.DeltaTime;
new MoveJob { DeltaTime = SystemAPI.Time.DeltaTime }
}
.ScheduleParallel();
}
}
The same loop as an IJobEntity
[BurstCompile]
partial struct MoveJob : IJobEntity
{
public float DeltaTime;
void Execute(TransformRef transform, in Velocity velocity)
{
transform.Position += velocity.Value * DeltaTime;
}
}
Burst-compiled and spread across worker threads.
Gameplay still stays in the MonoBehaviour.
Unite/Tokyo ECS For All IComponentData in the Inspector ● Add it with Add Component ● Edit its fields like any other component ● Works with Prefabs, Copy + Paste and Undo ● Saved in Scenes In development. Subject to change.
Unite/Tokyo ECS For All Whatʼs next 7.X
Unite/Tokyo ECS For All Whatʼs next 7.X ● Systems for MonoBehaviours Control when MonoBehaviours update relative to Systems
Unite/Tokyo ECS For All Whatʼs next 7.X ● Systems for MonoBehaviours Control when MonoBehaviours update relative to Systems ● Chunk serialisation in Scenes Optimised Entity loading when you load your Scene
Unite/Tokyo ECS For All Whatʼs next 7.X ● Systems for MonoBehaviours Control when MonoBehaviours update relative to Systems ● Chunk serialisation in Scenes Optimised Entity loading when you load your Scene ● GameObject Components in Entity Archetypes
Unite/Tokyo ECS For All Whatʼs next 7.X ● Systems for MonoBehaviours Control when MonoBehaviours update relative to Systems ● Chunk serialisation in Scenes Optimised Entity loading when you load your Scene ● GameObject Components in Entity Archetypes ● Pure Entities authoring directly in the Scene
Unite/Tokyo ECS For All Whatʼs next 7.X ● Systems for MonoBehaviours Control when MonoBehaviours update relative to Systems ● Chunk serialisation in Scenes Optimised Entity loading when you load your Scene ● GameObject Components in Entity Archetypes ● Pure Entities authoring directly in the Scene ● Mixed hierarchies of Entities and GameObjects
Unite/Tokyo ECS For All Whatʼs next 7.X ● Systems for MonoBehaviours Control when MonoBehaviours update relative to Systems ● Chunk serialisation in Scenes Optimised Entity loading when you load your Scene ● GameObject Components in Entity Archetypes ● Pure Entities authoring directly in the Scene ● Mixed hierarchies of Entities and GameObjects ● Optional Transform on GameObjects
The future vision
Unite/Tokyo ECS For All The vision: a scene that is 90% Entities The scene today In a complex scene, most things are made entirely of Unity types: Transform, Renderer, MeshFilter, Rigidbody. No MonoBehaviours. (conceptual)
Unite/Tokyo ECS For All The vision: a scene that is 90% Entities The scene today In a complex scene, most things are made entirely of Unity types: Transform, Renderer, MeshFilter, Rigidbody. No MonoBehaviours. So what if all of those were backed entirely by pure Entity data? (conceptual)
Unite/Tokyo ECS For All The vision: a scene that is 90% Entities Entities in grey (conceptual)
Unite/Tokyo ECS For All The vision: a scene that is 90% Entities Entities in grey Shipping Unity features powered by ECS Rendering, Lighting, Physics, … (conceptual)
Unite/Tokyo ECS For All The vision: a scene that is 90% Entities Entities in grey Shipping Unity features powered by ECS Rendering, Lighting, Physics, … All Entity data can load faster via chunks (conceptual)
Unite/Tokyo ECS For All The vision: a scene that is 90% Entities Entities in grey Shipping Unity features powered by ECS Rendering, Lighting, Physics, … All Entity data loads faster via chunks Same types, all usable from normal MonoBehaviours Remember: in C# theyʼre wrappers, so they keep working (conceptual)
Unite/Tokyo ECS For All The vision: a scene that is 90% Entities Entities in grey Shipping Unity features powered by ECS Rendering, Lighting, Physics, … All Entity data loads faster via chunks Same types, all usable from normal MonoBehaviours Remember: in C# theyʼre wrappers, so they keep working Keep using MonoBehaviours as you like …while passively benefiting from ECS internally (conceptual)
Thank you!