gamedev 2017 - Анатолій Ландишев "aaa architecture in unity3d"
TRANSCRIPT
AAA ARCHITECTURE IN
Speaker: Anatolii Landyshev
• Founder, CTO of Patriotic Games
• 6 years of experience in
http://patriotic.games
Anatolii Landyshev
Agenda• The goals of game architecture
• Unity architecture analysis• Components vs Inheritance• Singletons and Encapsulation
• Entity Component System (ECS)• Definition and advantages• ECS in Unity
Agenda• The goals of game architecture
• Unity architecture analysis• Components vs Inheritance• Singletons and Encapsulation
• Entity Component System (ECS)• Definition and advantages• ECS in Unity
Games vs Apps
Lots of real-time
simulations on single
screen
Look & feel
Experience
Fun
Content is over 50%
of the game
Perfect Game Architecture• Flexible
• Rapid prototyping
• “No Engineer required”
Agenda• The goals of game architecture
• Unity architecture analysis• Components vs Inheritance• Singletons and Encapsulation
• Entity Component System (ECS)• Definition and advantages• ECS in Unity
The easiest architecture in Unity
The easiest architecture in Unity
Check Zombie Toys on Asset Store
Agenda• The goals of game architecture
• Unity architecture analysis• Components vs Inheritance• Singletons and Encapsulation
• Entity Component System (ECS)• Definition and advantages• ECS in Unity
Components instead of Inheritance
Introducing Space Wars
MonoBehaviour
Player Spaceship
AIPlayer
HumanPlayer
Scout
Defender
Cruiser
MonoBehaviour
Player Spaceship
AIPlayer
HumanPlayer
Scout
Defender
Cruiser
MonoBehaviour
Player Spaceship
AIPlayer
HumanPlayer
Scout
Defender
Cruiser
AIPlayer
Defender
Gun
Composition over inheritance
AIPlayer
Defender
Gun
Composition over inheritance
AIPlayer
PlayerAI
RenderHealthTeam
Defender
MoveRenderHealthTeamGun
Components instead of inheritance
AIPlayer
PlayerAI
RenderHealthTeam
Defender
MoveRenderHealthTeamGun
Components instead of inheritance
AIPlayer
PlayerAI
RenderHealthTeamGun
Defender
MoveRenderHealthTeamGun
Components instead of inheritance
Components instead of Inheritance
Pros: flexibility
Cons: !code-sharing
Agenda• The goals of game architecture
• Unity architecture analysis• Components vs Inheritance• Singletons and Encapsulation
• Entity Component System (ECS)• Definition and advantages• ECS in Unity
Singleton GameManager
Singleton GameManager
breaksEncapsulatio
n
Data Instructions
Application
Data Instructions
Application Code
Variables
Functions (Methods)
Variables + Functions = Procedural Programming
- the goal of OOP
Modularity
Goals of OOP
Scalability
Modularity
Goals of OOP
Scalability
Encapsulation
What is an object?
What is an object?
What is an object?
Object-oriented program
Messages may read and modify state
Messages may read and modify state
Messages may read and modify state
The moment objects are sharedwe lose Encapsulation
Only way to encapsulate objects = strict hierarchy of references/messages
Only way to encapsulate objects = strict hierarchy of references/messages
Use of singleton GameManager
Expectation Reality
Singleton GameManager
Pros: simple
Cons: non-modular code
What to use instead:strict hierarchy of references/messages?
Pros: modularity
Cons: lack of flexibility
What about cross-cutting concerns?
What about cross-cutting concerns?
Expectation Reality
What to use instead:strict hierarchy of references/messages?
Pros: modularity
Cons: lack of flexibility
Absence of structure is better than bad structure
Data Instructions
Application
Agenda• The goals of game architecture
• Unity architecture analysis• Components vs Inheritance• Singletons and Encapsulation
• Entity Component System (ECS)• Definition and advantages• ECS in Unity
ECS is mainstream in
MMO & AAA games
Unity
SceneGameObjectGameObjectGameObject
GameObject
MonoBehaviourMonoBehaviourMonoBehaviour
MonoBehaviour
DataBehaviour
Unity
SceneGameObjectGameObjectGameObject
GameObject
MonoBehaviourMonoBehaviourMonoBehaviour
MonoBehaviour
DataBehaviour
Context
EntityEntityEntity
EntityComponentComponentComponent
Component
Data
ECS
Unity
SceneGameObjectGameObjectGameObject
GameObject
MonoBehaviourMonoBehaviourMonoBehaviour
MonoBehaviour
DataBehaviour
Context
EntityEntityEntity
EntityComponentComponentComponent
Component
Data
ECS No Behaviour in Components!
OK, WHAT ABOUT LOGIC?
Systemschain of responsibility
Systemschain of responsibility
ECS advantages
• Testability
• Co-dependent logic
• Co-dependent logic
• Querying
OK, WHAT ABOUT PERFORMANCE?
OK, WHAT ABOUT PERFORMANCE?•Multithreading almost for free•Data locality
Agenda• The goals of game architecture
• Unity architecture analysis• Components vs Inheritance• Singletons and Encapsulation
• Entity Component System (ECS)• Definition and advantages• ECS in Unity
“Entity Systems are the future of MMOG development”
Adam Martin (t-machine.org)
ECS frameworks for Unity• Entitas C# -
https://github.com/sschmid/Entitas-CSharp
• Artemis C# - https://github.com/thelinuxlich/artemis_CSharp
• uFrame ECS – https://github.com/uFrame/ECS
• EgoCS - https://github.com/andoowhy/EgoCS
ECS Framework for Unitytinyurl.com/entitas
or search for ENTITAS UNITY on YouTube
Entitas advantages:
is open sourcegithub.com/sschmid/Entitas-
CSharp
Entitas advantages:
• It’s open-source
Excellent community & support
Entitas advantages:
• It’s open-source• Excellent community & support
Entitas advantages:
• It’s open-source• Excellent community & support• Code-sharing
Unity Visual Debug
Entitas advantages:
• It’s open-source• Excellent community & support• Code-sharing• Special debug features for Unity
Entitas advantages:
• It’s open-source• Excellent community & support• Code-sharing• Special debug features for Unity• Great performance
Unity vs Entitas Performance1000 objects with 2 components
• Memory: 9x (2.9MB vs 0.32MB)
• CPU: 17x (105ms vs 6ms)
Unity vs Entitas Performance1000 objects with 2 components
• reuses Entities• reuses Components• caches Groups• can index Components
Entitas…
• Initialize Systems• Execute Systems• Reactive Systems• only processes changed
entities
Systems in Entitas
#madeWithEntitas
Agenda• The goals of game architecture
• Unity architecture analysis• Components vs Inheritance• Singletons and Encapsulation
• Entity Component System (ECS)• Definition and advantages• ECS in Unity
Questions?