Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

1,195 views

Published on

Using a strict Entity Component System (ECS) architecture in Unity helped me to achieve easy to test, robust and scalable game logic. I want to show you how you can benefit from using Entitas in you game. Entitas is an open source ECS library which proofs how ECS and Unity can co-exist and empower developers to have a simple, flexible and clean architecture.

Published in: Software
  • Be the first to comment

Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

  1. 1. ENTITY COMPONENT SYSTEM ARCHITECTUREClean, fast and simple with Entitas and Unity
  2. 2. ARCHITECTURE why it matters
  3. 3. Simon Schmid Engineer
  4. 4. GAME DEVELOPMENT is hard
  5. 5. GAME ENGINE
  6. 6. ARCHITECTURE still?
  7. 7. DESIGN PATTERNS
  8. 8. WHY SHOULD I care
  9. 9. WHY SHOULD I care
  10. 10. ENTITY COMPONENT SYSTEM ARCHITECTURE
  11. 11. ENTITAS#1 ECS ON GITHUB
  12. 12. ENTITAS clean fast simple
  13. 13. ENTITASINTRODUCTION
  14. 14. UNITY COMPONENTS: Data + Behaviour ENTITAS COMPONENTS Data only
  15. 15. public class Archer : Troop { public int health; public float speed; // ... void Awake() { // ... } void Start() { // ... } void Update() { // ... } }
  16. 16. public class Archer : Troop { // Inheritance public int health; public float speed; // Data // ... void Awake() { // ... } // Initialization void Start() { // ... } void Update() { // ... // Update } }
  17. 17. // Data only - no behaviour public class PositionComponent : IComponent { public Vector3 value; } public class MovableComponent : IComponent { }
  18. 18. +------------------+ | Pool | |------------------| | 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 | +------------------+ +-----------+ +-----------+ | | | +-------------+ | | e | Groups | | e e | +---> | +------------+ | e | | | | e | e | e | +--------|----+ e | | e | | e e | +------------+
  19. 19. LOGIC?
  20. 20. Games are interactive simulations — Maxim Zaks
  21. 21. public class MovementSystem : IExecuteSystem { public void Execute() { var movables = Pools.pool.GetGroup( Matcher.AllOf( Matcher.Velocity, Matcher.Position )); foreach (var e in movables.GetEntities()) { var pos = e.position.value; e.ReplacePosition(pos + e.velocity.value); } } }
  22. 22. SINGLE RESPONSIBILITY principle
  23. 23. SYSTEMS Chain of Responsibility +------------+ +------------+ +------------+ +------------+ | | | | | | | | | System | +---> | System | +---> | System | +---> | System | | | | | | | | | +------------+ +------------+ +------------+ +------------+
  24. 24. SYSTEMS Chain of Responsibility |-------------------------------- Game Loop --------------------------------| +------------+ +------------+ +------------+ +------------+ | | | | | | | | | System | +---> | System | +---> | System | +---> | System | | | | | | | | | +------------+ +------------+ +------------+ +------------+
  25. 25. SYSTEMS IN ENTITAS - Initialize System - Execute System - Reactive System
  26. 26. DEMO Match One
  27. 27. ENTITAS ▸ clean fast simple
  28. 28. CLEAN Separation of concerns Composition over Inheritance Single responsibility principle Consistency
  29. 29. SEPARATION OF CONCERNS
  30. 30. Composition over INHERITANCE
  31. 31. SINGLE RESPONSIBILITY principle
  32. 32. public class MovementSystem : IExecuteSystem { public void Execute() { var movables = Pools.pool.GetGroup( Matcher.AllOf( Matcher.Velocity, Matcher.Position )); foreach (var e in movables.GetEntities()) { var pos = e.position.value; e.ReplacePosition(pos + e.velocity.value); } } }
  33. 33. it["adds velocity to position"] = () => { // given var pool = Pools.sharedInstance.core; var entity = pool.CreateEntity() .AddPosition(Vector3.one) .AddVelocity(Vector3.one); var system = pool.CreateSystem(new MovementSystem()); // when system.Execute(); // then entity.position.value.should_be(new Vector3(2, 2, 2)); };
  34. 34. CONSISTENCY
  35. 35. CLEAN Separation of concerns Composition over Inheritance Single responsibility principle Consistency
  36. 36. ENTITAS clean ▸ fast simple
  37. 37. UNITY VS ENTITAS: Objects 1000 objects with 2 components Memory: 9x (2.9 MB vs 0.32 MB) CPU: 17x (105 ms vs 6 ms)
  38. 38. ENTITAS VS UNITY: Logic update 25000 objects Memory: 5x (36.4 MB vs 7.6 MB) CPU: 2x (20.5 ms vs 9.6 ms)
  39. 39. UNITY BLOG 10000 Update() calls by Valentin Simonov
  40. 40. ENTITAS clean fast ▸ simple
  41. 41. SIMPLE similar to Unity simple conventions easy to add features Visual Debugging Reusing code
  42. 42. SYSTEMS Chain of Responsibility +------------+ +------------+ +------------+ +------------+ | | | | | | | | | System | +---> | System | +---> | System | +---> | System | | | | | | | | | +------------+ +------------+ +------------+ +------------+
  43. 43. SYSTEMS Chain of Responsibility +------------+ +------------+ +------------+ | | | | | | | System | +---> | System | +------------------------> | System | | | | | | | +------------+ +------------+ +------------+
  44. 44. SYSTEMS Chain of Responsibility +------------+ +------------+ +------------+ +------------+ | | | | | | | | | System | +---> | System | +---> | System | +---> | System | | | | | | | | | +------------+ +------------+ +------------+ +------------+
  45. 45. SIMPLE similar to Unity simple conventions easy to add features Visual Debugging Reusing code
  46. 46. ENTITAS IS open source GITHUB.COM/SSCHMID/ENTITAS-CSHARP
  47. 47. WOOGA.COM/JOBS
  48. 48. QUESTIONS? #ENTITAS GITHUB.COM/SSCHMID/ENTITAS-CSHARP

×