SlideShare a Scribd company logo
1 of 56
Download to read offline
Entity system architecture
with Unity
Maxim Zaks | @icex33 | github.com/mzaks
Simon Schmid | @s_schmid | github.com/sschmid
Wooga
Unity pain points
4 Testability
4 Code sharing
4 Co-dependent logic
4 Querying
4 Deleting code
Testability
Code sharing
Co-dependent logic
Co-dependent logic
Co-dependent logic
Querying
Deleting code
Entitas
Match One Demo
Components are just data
4 no Methods, no Start(), no Update()
4 no inheritance
+-----------+
| Component |
|-----------|
| Data |
+-----------+
PositionComponent
using Entitas;
public class PositionComponent : IComponent
{
public int x;
public int y;
}
GameBoardElementComponent
using Entitas;
public class GameBoardElementComponent : IComponent
{
}
Entity is a container for components
+-----------+
| Entity |
|-----------|
| Component |
| |
| Component |
| |
| Component |
+-----------+
Entity
4 Add Components
4 Replace Components
4 Remove Components
Create Blocker Entity
public static Entity CreateBlocker(this Pool pool, int x, int y)
{
return pool.CreateEntity()
.IsGameBoardElement(true)
.AddPosition(x, y)
.AddResource(Res.Blocker);
}
Pool contains all entities
+------------------+
| Pool |
|------------------|
| e e |
| e e |
| e e |
| e e e |
| e e |
| e e |
| e e e |
| e e e |
+------------------+
Pool
4 Create Entity
4 Destroy Entity
4 Get all Entities
4 Get Group
Groups are subsets of entities
4 Performance optimization for querying
4 Matcher is a filter description
+-------------+ Groups:
| e | Subsets of entities in the pool
| e e | for blazing fast querying
| +------------+
| e | | |
| e | e | e |
+--------|----+ e |
| e |
| e e |
+------------+
Get Group from pool
_pool.GetGroup(
Matcher.AllOf(
Matcher.GameBoardElement,
Matcher.Position
)
);
+------------------+
| Pool | Entitas in a nutshell
|------------------|
| e e | +-----------+
| e e---|----> | Entity |
| e e | |-----------|
| e e e | | Component |
| e e | | | +-----------+
| e e | | Component-|----> | Component |
| e e e | | | |-----------|
| e e e | | Component | | Data |
+------------------+ +-----------+ +-----------+
|
|
| +-------------+ Groups:
| | e | Subsets of entities in the pool
| | e e | for blazing fast querying
+---> | +------------+
| e | | |
| e | e | e |
+--------|----+ e |
| e |
| e e |
+------------+
Behaviour
System
4 Start / Execute
4 No State!!!
+------------------+ +-----------------------------+
| Pool | | System |
|------------------| |-----------------------------|
| e e | | - Execute |
| e e | | |
| e e | | +-------------+ |
| e e e | | | e | Groups |
| e e |+----|->| e e | |
| e e | | | +------------+ |
| e e e | | | e | | | |
| e e e | | | e | e | e | |
+------------------+ | +--------|----+ e | |
| | e | |
| | e e | |
| +------------+ |
+-----------------------------+
MoveSystem
public void Execute() {
var movables = _pool.GetGroup(
Matcher.AllOf(
Matcher.Move,
Matcher.Position
));
foreach (var e in movables.GetEntities()) {
var move = e.move;
var pos = e.position;
e.ReplacePosition(pos.x, pos.y + move.speed, pos.z);
}
}
Chain of Responsibility
| |
|-------------------------------- Game Loop --------------------------------|
| |
+------------+ +------------+ +------------+ +------------+
| | | | | | | |
| System | +---> | System | +---> | System | +---> | System |
| | | | | | | |
+------------+ +------------+ +------------+ +------------+
return new Systems()
.Add( pool.CreateGameBoardSystem ())
.Add( pool.CreateCreateGameBoardCacheSystem ())
.Add( pool.CreateFallSystem ())
.Add( pool.CreateFillSystem ())
.Add( pool.CreateProcessInputSystem ())
.Add( pool.CreateRemoveViewSystem ())
.Add( pool.CreateAddViewSystem ())
.Add( pool.CreateRenderPositionSystem ())
.Add( pool.CreateDestroySystem ())
.Add( pool.CreateScoreSystem ());
Reacting to changes in a Group
4 On Entity added
4 On Entity removed
ScoreLabelController
void Start() {
_pool.GetGroup(Matcher.Score).OnEntityAdded +=
(group, entity) => updateScore(entity.score.value);
updateScore(_pool.score.value);
}
void updateScore(int score) {
_label.text = "Score " + score;
}
Reactive System
4 Executed only when entities in a group have changed
4 Aggregate and process changes
Render Position System
public class RenderPositionSystem : IReactiveSystem {
public IMatcher trigger { get { return Matcher.AllOf(Matcher.Position, Matcher.View); } }
public GroupEventType eventType { get { return GroupEventType.OnEntityAdded; } }
public void Execute(Entity[] entities) {
foreach (var e in entities) {
var pos = e.position;
e.view.gameObject.transform.position = new Vector3(pos.x, pos.y);
}
}
}
Optimizations
Components
mutable vs immutable
Entity
Dictionary vs Array
Dictionary
e.AddComponent(new PositionComponent());
var component = e.GetComponent<PositionComponent>();
Array
e.AddComponent(new PositionComponent(), 5);
var component = (PositionComponent)e.GetComponent(5);
Code Generator
Before Code Generation
PositionComponent component;
if (e.HasComponent(ComponentIds.Position)) {
e.WillRemoveComponent(ComponentIds.Position);
component = (PositionComponent)e.GetComponent(ComponentIds.Position);
} else {
component = new PositionComponent();
}
component.x = 10;
component.y = 10;
e.ReplaceComponent(ComponentIds.Position, component);
After Code Generation
e.ReplacePosition(10, 10);
Code Generator Demo
var pool = Pools.pool;
var e = pool.CreateEntity();
e.AddPosition(1, 2, 3);
e.ReplacePosition(4, 5, 6);
e.RemovePosition();
var posX = e.position.x;
var hasPos = e.hasPosition;
e.isMovable = true;
e.isMovable = false;
var isMovable = e.isMovable;
Visual Debugging Demo
Entitas is
open sourcegithub.com/sschmid/Entitas-CSharp
Recap
Unity pain points
4 Testability
4 Code sharing
4 Co-dependent logic
4 Querying
4 Deleting code
Advantages
4 Straightforward to achieve Determinism and
therefore Replay
4 Simulation Speed (2x, 4x)
4 Headless Simulation, just remove systems which rely
on GameObjects (render systems)
4 Save Game (Serialization / Deserialization) send
data to backend on change
Q&AMaxim Zaks | @icex33 | github.com/mzaks
Simon Schmid | @s_schmid | github.com/sschmid
tinyurl.com/entitas

More Related Content

What's hot

Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Quantum Computing for app programmer
Quantum Computing for app programmerQuantum Computing for app programmer
Quantum Computing for app programmerKyunam Cho
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語Kiyotaka Oku
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with SpockAlexander Tarlinder
 
The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180Mahmoud Samir Fayed
 
Clustering your Application with Hazelcast
Clustering your Application with HazelcastClustering your Application with Hazelcast
Clustering your Application with HazelcastHazelcast
 
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
Vielseitiges In-Memory Computing mit Apache Ignite und KubernetesVielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
Vielseitiges In-Memory Computing mit Apache Ignite und KubernetesQAware GmbH
 
Spark RDD-DF-SQL-DS-Spark Hadoop User Group Munich Meetup 2016
Spark RDD-DF-SQL-DS-Spark Hadoop User Group Munich Meetup 2016Spark RDD-DF-SQL-DS-Spark Hadoop User Group Munich Meetup 2016
Spark RDD-DF-SQL-DS-Spark Hadoop User Group Munich Meetup 2016Comsysto Reply GmbH
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyBen Hall
 

What's hot (10)

Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Quantum Computing for app programmer
Quantum Computing for app programmerQuantum Computing for app programmer
Quantum Computing for app programmer
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語
 
Java Puzzlers
Java PuzzlersJava Puzzlers
Java Puzzlers
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with Spock
 
The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180
 
Clustering your Application with Hazelcast
Clustering your Application with HazelcastClustering your Application with Hazelcast
Clustering your Application with Hazelcast
 
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
Vielseitiges In-Memory Computing mit Apache Ignite und KubernetesVielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
 
Spark RDD-DF-SQL-DS-Spark Hadoop User Group Munich Meetup 2016
Spark RDD-DF-SQL-DS-Spark Hadoop User Group Munich Meetup 2016Spark RDD-DF-SQL-DS-Spark Hadoop User Group Munich Meetup 2016
Spark RDD-DF-SQL-DS-Spark Hadoop User Group Munich Meetup 2016
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) Family
 

Similar to Entity system architecture with Entitas for Unity

Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Maxim Zaks
 
MySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesMySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesDamien Seguy
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfzJoshua Thijssen
 
Observability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System TablesObservability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System TablesInfluxData
 
BigQuery implementation
BigQuery implementationBigQuery implementation
BigQuery implementationSimon Su
 
M|18 User Defined Function
M|18 User Defined FunctionM|18 User Defined Function
M|18 User Defined FunctionMariaDB plc
 
The story and tech of Read the Docs
The story and tech of Read the DocsThe story and tech of Read the Docs
The story and tech of Read the Docsericholscher
 
ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!
ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!
ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!SPB SQA Group
 
CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster
CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster
CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster Shaun Domingo
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기Yeongseon Choe
 
How to build and run oci containers
How to build and run oci containersHow to build and run oci containers
How to build and run oci containersSpyros Trigazis
 
Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...
Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...
Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...Guillaume Finance
 
Cruel (SQL) Intentions
Cruel (SQL) IntentionsCruel (SQL) Intentions
Cruel (SQL) Intentionsezra_c
 
Planet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance EnhancementPlanet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance Enhancementup2soul
 
忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demo忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demoFumihito Yokoyama
 
Quick and Dirty GUI Applications using GUIDeFATE
Quick and Dirty GUI Applications using GUIDeFATEQuick and Dirty GUI Applications using GUIDeFATE
Quick and Dirty GUI Applications using GUIDeFATEConnie New
 
Introduction to Git Source Control
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source ControlJohn Valentino
 

Similar to Entity system architecture with Entitas for Unity (20)

Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015
 
MySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesMySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queries
 
Pyspark
PysparkPyspark
Pyspark
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Observability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System TablesObservability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System Tables
 
BigQuery implementation
BigQuery implementationBigQuery implementation
BigQuery implementation
 
M|18 User Defined Function
M|18 User Defined FunctionM|18 User Defined Function
M|18 User Defined Function
 
The story and tech of Read the Docs
The story and tech of Read the DocsThe story and tech of Read the Docs
The story and tech of Read the Docs
 
ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!
ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!
ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!
 
CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster
CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster
CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기
 
How to build and run oci containers
How to build and run oci containersHow to build and run oci containers
How to build and run oci containers
 
Real
RealReal
Real
 
Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...
Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...
Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...
 
Cruel (SQL) Intentions
Cruel (SQL) IntentionsCruel (SQL) Intentions
Cruel (SQL) Intentions
 
Planet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance EnhancementPlanet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance Enhancement
 
忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demo忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demo
 
Quick and Dirty GUI Applications using GUIDeFATE
Quick and Dirty GUI Applications using GUIDeFATEQuick and Dirty GUI Applications using GUIDeFATE
Quick and Dirty GUI Applications using GUIDeFATE
 
Introduction to Git Source Control
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
 
Perf Tuning Short
Perf Tuning ShortPerf Tuning Short
Perf Tuning Short
 

Recently uploaded

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 

Recently uploaded (20)

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 

Entity system architecture with Entitas for Unity

  • 2. Maxim Zaks | @icex33 | github.com/mzaks Simon Schmid | @s_schmid | github.com/sschmid
  • 4.
  • 5. Unity pain points 4 Testability 4 Code sharing 4 Co-dependent logic 4 Querying 4 Deleting code
  • 13.
  • 15.
  • 16. Components are just data 4 no Methods, no Start(), no Update() 4 no inheritance +-----------+ | Component | |-----------| | Data | +-----------+
  • 17. PositionComponent using Entitas; public class PositionComponent : IComponent { public int x; public int y; }
  • 18. GameBoardElementComponent using Entitas; public class GameBoardElementComponent : IComponent { }
  • 19. Entity is a container for components +-----------+ | Entity | |-----------| | Component | | | | Component | | | | Component | +-----------+
  • 20. Entity 4 Add Components 4 Replace Components 4 Remove Components
  • 21. Create Blocker Entity public static Entity CreateBlocker(this Pool pool, int x, int y) { return pool.CreateEntity() .IsGameBoardElement(true) .AddPosition(x, y) .AddResource(Res.Blocker); }
  • 22. Pool contains all entities +------------------+ | Pool | |------------------| | e e | | e e | | e e | | e e e | | e e | | e e | | e e e | | e e e | +------------------+
  • 23. Pool 4 Create Entity 4 Destroy Entity 4 Get all Entities 4 Get Group
  • 24. Groups are subsets of entities 4 Performance optimization for querying 4 Matcher is a filter description +-------------+ Groups: | e | Subsets of entities in the pool | e e | for blazing fast querying | +------------+ | e | | | | e | e | e | +--------|----+ e | | e | | e e | +------------+
  • 25. Get Group from pool _pool.GetGroup( Matcher.AllOf( Matcher.GameBoardElement, Matcher.Position ) );
  • 26. +------------------+ | Pool | Entitas in a nutshell |------------------| | e e | +-----------+ | e e---|----> | Entity | | e e | |-----------| | e e e | | Component | | e e | | | +-----------+ | e e | | Component-|----> | Component | | e e e | | | |-----------| | e e e | | Component | | Data | +------------------+ +-----------+ +-----------+ | | | +-------------+ Groups: | | e | Subsets of entities in the pool | | e e | for blazing fast querying +---> | +------------+ | e | | | | e | e | e | +--------|----+ e | | e | | e e | +------------+
  • 28. System 4 Start / Execute 4 No State!!!
  • 29. +------------------+ +-----------------------------+ | Pool | | System | |------------------| |-----------------------------| | e e | | - Execute | | e e | | | | e e | | +-------------+ | | e e e | | | e | Groups | | e e |+----|->| e e | | | e e | | | +------------+ | | e e e | | | e | | | | | e e e | | | e | e | e | | +------------------+ | +--------|----+ e | | | | e | | | | e e | | | +------------+ | +-----------------------------+
  • 30. MoveSystem public void Execute() { var movables = _pool.GetGroup( Matcher.AllOf( Matcher.Move, Matcher.Position )); foreach (var e in movables.GetEntities()) { var move = e.move; var pos = e.position; e.ReplacePosition(pos.x, pos.y + move.speed, pos.z); } }
  • 31. Chain of Responsibility | | |-------------------------------- Game Loop --------------------------------| | | +------------+ +------------+ +------------+ +------------+ | | | | | | | | | System | +---> | System | +---> | System | +---> | System | | | | | | | | | +------------+ +------------+ +------------+ +------------+
  • 32. return new Systems() .Add( pool.CreateGameBoardSystem ()) .Add( pool.CreateCreateGameBoardCacheSystem ()) .Add( pool.CreateFallSystem ()) .Add( pool.CreateFillSystem ()) .Add( pool.CreateProcessInputSystem ()) .Add( pool.CreateRemoveViewSystem ()) .Add( pool.CreateAddViewSystem ()) .Add( pool.CreateRenderPositionSystem ()) .Add( pool.CreateDestroySystem ()) .Add( pool.CreateScoreSystem ());
  • 33. Reacting to changes in a Group 4 On Entity added 4 On Entity removed
  • 34. ScoreLabelController void Start() { _pool.GetGroup(Matcher.Score).OnEntityAdded += (group, entity) => updateScore(entity.score.value); updateScore(_pool.score.value); } void updateScore(int score) { _label.text = "Score " + score; }
  • 35. Reactive System 4 Executed only when entities in a group have changed 4 Aggregate and process changes
  • 36. Render Position System public class RenderPositionSystem : IReactiveSystem { public IMatcher trigger { get { return Matcher.AllOf(Matcher.Position, Matcher.View); } } public GroupEventType eventType { get { return GroupEventType.OnEntityAdded; } } public void Execute(Entity[] entities) { foreach (var e in entities) { var pos = e.position; e.view.gameObject.transform.position = new Vector3(pos.x, pos.y); } } }
  • 39.
  • 40.
  • 42. Dictionary e.AddComponent(new PositionComponent()); var component = e.GetComponent<PositionComponent>(); Array e.AddComponent(new PositionComponent(), 5); var component = (PositionComponent)e.GetComponent(5);
  • 43.
  • 44.
  • 46. Before Code Generation PositionComponent component; if (e.HasComponent(ComponentIds.Position)) { e.WillRemoveComponent(ComponentIds.Position); component = (PositionComponent)e.GetComponent(ComponentIds.Position); } else { component = new PositionComponent(); } component.x = 10; component.y = 10; e.ReplaceComponent(ComponentIds.Position, component);
  • 49. var pool = Pools.pool; var e = pool.CreateEntity(); e.AddPosition(1, 2, 3); e.ReplacePosition(4, 5, 6); e.RemovePosition(); var posX = e.position.x; var hasPos = e.hasPosition; e.isMovable = true; e.isMovable = false; var isMovable = e.isMovable;
  • 51.
  • 53. Recap
  • 54. Unity pain points 4 Testability 4 Code sharing 4 Co-dependent logic 4 Querying 4 Deleting code
  • 55. Advantages 4 Straightforward to achieve Determinism and therefore Replay 4 Simulation Speed (2x, 4x) 4 Headless Simulation, just remove systems which rely on GameObjects (render systems) 4 Save Game (Serialization / Deserialization) send data to backend on change
  • 56. Q&AMaxim Zaks | @icex33 | github.com/mzaks Simon Schmid | @s_schmid | github.com/sschmid tinyurl.com/entitas