SlideShare a Scribd company logo
Architecting Games in
Unity
Common patterns for developing games in Unity
If this was your house, what would you do?
Broken Windows
•Fix the windows.
•In New York City, Albuquerque and The Netherlands, improving the
physical appearance of a neighbourhood has been shown to reduce
crime and increase quality of life.
•People are influenced by their environment:
• Social norms and conformity
• Routine monitoring
Ah, Freedom!
•Unity gives you a rich set of building blocks that can be used to
construct any type of game.
•Unity is flexible.
•There are hundreds of ways to build projects.
•And developers use ALL of them!
Architecture for Games
•But let's look at what you need
•And let's create a structure that can be reused for efficiency and
robustness
Good Architecture = Good Standards
•Use C#
•Naming conventions
• Use descriptive names
• Use standardized capitalization
• In Unity don’t be afraid of using spaces in names
•Logical folder structure
•Zero-tolerance for warnings and errors
•Zero-tolerance for runtime memory allocation
Core Application Logic
•Main Controller
• Base controller to manage high level application
• Uses public static methods so everyone can access it
• Uses Object.DontDestroyOnLoad so it is available throughout the project
•Scenes
• Other scenes are loaded on top of this.
• MainController loads and unloads other scenes and cleans up.
Main Controller – Reset State
•Call GC.Collect to try to reclaim some memory.
Main Controller – Preload State
•Start loading the level asynchronously and change state to Load
Main Controller – Load State
•Keep going until loading is done
Main Controller – Unload State
•Resources.UnloadUnusedAssets()
•Keep going until Unloading is done
Main Controller – Postload State
•Do things immediately after loading
•Update currentSceneName
Main Controller – Ready State
•Call GC.Collect to try to reclaim some memory.
• Avoid this if you have unused assets in the scene that may be used later.
•Do things just before beginning: e.g.: Get User Input to Start
Main Controller – Run State
•We stay here until currentLevelName != nextLevelName
•This can be changed by calling SwitchScene static public method on
the Main Controller from anywhere
Scene State Machine Implementation
•We can use a switch-case
• Gets difficult to maintain and read
•We can use delegates
• Unfortunately, setting a delegate allocates memory
•So we use an array of delegates.
Scene State Machine Implementation
•Example Implementation
• MainController, MenuController and GameController
• Let’s look at the Profiler too!
Implementing Gameplay
•Controllers manage the objects
•Inter-object communication
• Static public methods
• Temporary public instance methods
• Messages, events
•Most common are:
• Singletons
• “Pool” controllers
Singleton
•Only one of them in the game
•Static public methods
•Examples:
• Score
• Player
• World
• Game
Singleton
•Example Implementation
Pool Based Objects
•Numerous instances in the game
•Limited number at any one time
•Preload simultaneously used quantity and disable
•Static public method to “spawn” one finds first disabled one and
enables it
•Examples:
• Explosions
• Bullets
• Enemies
• Scenery
GameObjects are loaded from
storage and placed in a pool and
disabled.
Object Pool
Storage
Pool Based Objects
GameObjects are activated when
needed.
Object Pool
Storage
Pool Based Objects
GameObjects are deactivated
when no longer needed. This
returns them to the pool.
Object Pool
Storage
Pool Based Objects
Pool Based Objects
•Example Implementation
Download
•Find the Template.zip here:
http://goo.gl/8WZGxn
Best-Practices
•Use C#
•Naming conventions
•Logical folder structure
•Zero-tolerance for warnings and errors
•Zero-tolerance for runtime memory allocation
Thank You!
Rustum Scammell
Email: rus@unity3d.com
Skype: rustumscammell

More Related Content

Viewers also liked

OGDC 2014: Build your own particle system
OGDC 2014: Build your own particle systemOGDC 2014: Build your own particle system
OGDC 2014: Build your own particle system
GameLandVN
 
OGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dxOGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dx
GameLandVN
 
OGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
OGDC 2014: Sky Garden Mobile conceptualization: From PC to MobileOGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
OGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
GameLandVN
 
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
GameLandVN
 
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile gameOGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
GameLandVN
 
OGDC 2014: Cross Platform Mobile Game Application Development
OGDC 2014: Cross Platform Mobile Game Application DevelopmentOGDC 2014: Cross Platform Mobile Game Application Development
OGDC 2014: Cross Platform Mobile Game Application Development
GameLandVN
 
OGDC 2014: 10 bits of business/design wisdom
OGDC 2014: 10 bits of business/design wisdomOGDC 2014: 10 bits of business/design wisdom
OGDC 2014: 10 bits of business/design wisdom
GameLandVN
 
OGDC 2014: Component based entity system mobile game development
OGDC 2014: Component based entity system mobile game developmentOGDC 2014: Component based entity system mobile game development
OGDC 2014: Component based entity system mobile game development
GameLandVN
 
OGDC 2014: 2D Animation using After Effect for mobile game
OGDC 2014: 2D Animation using After Effect for mobile gameOGDC 2014: 2D Animation using After Effect for mobile game
OGDC 2014: 2D Animation using After Effect for mobile game
GameLandVN
 

Viewers also liked (9)

OGDC 2014: Build your own particle system
OGDC 2014: Build your own particle systemOGDC 2014: Build your own particle system
OGDC 2014: Build your own particle system
 
OGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dxOGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dx
 
OGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
OGDC 2014: Sky Garden Mobile conceptualization: From PC to MobileOGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
OGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
 
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
 
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile gameOGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
 
OGDC 2014: Cross Platform Mobile Game Application Development
OGDC 2014: Cross Platform Mobile Game Application DevelopmentOGDC 2014: Cross Platform Mobile Game Application Development
OGDC 2014: Cross Platform Mobile Game Application Development
 
OGDC 2014: 10 bits of business/design wisdom
OGDC 2014: 10 bits of business/design wisdomOGDC 2014: 10 bits of business/design wisdom
OGDC 2014: 10 bits of business/design wisdom
 
OGDC 2014: Component based entity system mobile game development
OGDC 2014: Component based entity system mobile game developmentOGDC 2014: Component based entity system mobile game development
OGDC 2014: Component based entity system mobile game development
 
OGDC 2014: 2D Animation using After Effect for mobile game
OGDC 2014: 2D Animation using After Effect for mobile gameOGDC 2014: 2D Animation using After Effect for mobile game
OGDC 2014: 2D Animation using After Effect for mobile game
 

Similar to OGDC 2014: Architecting Games in Unity

Scalable game-servers-tgc
Scalable game-servers-tgcScalable game-servers-tgc
Scalable game-servers-tgc
Ashkan Saeedi Mazdeh
 
Lecture 8 - What is Game AI? Final Thoughts
Lecture 8 - What is Game AI? Final ThoughtsLecture 8 - What is Game AI? Final Thoughts
Lecture 8 - What is Game AI? Final Thoughts
Luke Dicken
 
stackconf 2022: Infrastructure Automation (anti) patterns
stackconf 2022: Infrastructure Automation (anti) patternsstackconf 2022: Infrastructure Automation (anti) patterns
stackconf 2022: Infrastructure Automation (anti) patterns
NETWAYS
 
Infrastructure as Code Patterns
Infrastructure as Code PatternsInfrastructure as Code Patterns
Infrastructure as Code Patterns
Kris Buytaert
 
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Lviv Startup Club
 
2D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 2014
2D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 20142D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 2014
2D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 2014
Murat Gürel
 
Procedural Processes - Lessons Learnt from Automated Content Generation in "E...
Procedural Processes - Lessons Learnt from Automated Content Generation in "E...Procedural Processes - Lessons Learnt from Automated Content Generation in "E...
Procedural Processes - Lessons Learnt from Automated Content Generation in "E...
Luke Dicken
 
0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri0507 057 01 98 * Adana Cukurova Klima Servisleri
Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark HarknessOptimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harkness
ozlael ozlael
 
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Unity Technologies
 
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen..."Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
ConSol Consulting & Solutions Software GmbH
 
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen..."Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
ConSol Consulting & Solutions Software GmbH
 
CNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgCNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbg
Sam Bowne
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d Game
Isfand yar Khan
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
Dave Cross
 
InfectNet Technical
InfectNet TechnicalInfectNet Technical
InfectNet Technical
Attila Bagossy
 
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
DevGAMM Conference
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptx
NgLQun
 
Enterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptEnterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScript
Troy Miles
 
Practical Windows Kernel Exploitation
Practical Windows Kernel ExploitationPractical Windows Kernel Exploitation
Practical Windows Kernel Exploitation
zeroSteiner
 

Similar to OGDC 2014: Architecting Games in Unity (20)

Scalable game-servers-tgc
Scalable game-servers-tgcScalable game-servers-tgc
Scalable game-servers-tgc
 
Lecture 8 - What is Game AI? Final Thoughts
Lecture 8 - What is Game AI? Final ThoughtsLecture 8 - What is Game AI? Final Thoughts
Lecture 8 - What is Game AI? Final Thoughts
 
stackconf 2022: Infrastructure Automation (anti) patterns
stackconf 2022: Infrastructure Automation (anti) patternsstackconf 2022: Infrastructure Automation (anti) patterns
stackconf 2022: Infrastructure Automation (anti) patterns
 
Infrastructure as Code Patterns
Infrastructure as Code PatternsInfrastructure as Code Patterns
Infrastructure as Code Patterns
 
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
 
2D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 2014
2D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 20142D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 2014
2D Endless Runner in Unity for Mobile - GDG DevFest Istanbul 2014
 
Procedural Processes - Lessons Learnt from Automated Content Generation in "E...
Procedural Processes - Lessons Learnt from Automated Content Generation in "E...Procedural Processes - Lessons Learnt from Automated Content Generation in "E...
Procedural Processes - Lessons Learnt from Automated Content Generation in "E...
 
0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri
 
Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark HarknessOptimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harkness
 
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
 
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen..."Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
 
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen..."Using Automation Tools To Deploy And Operate Applications In Real World Scen...
"Using Automation Tools To Deploy And Operate Applications In Real World Scen...
 
CNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgCNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbg
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d Game
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
InfectNet Technical
InfectNet TechnicalInfectNet Technical
InfectNet Technical
 
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptx
 
Enterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptEnterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScript
 
Practical Windows Kernel Exploitation
Practical Windows Kernel ExploitationPractical Windows Kernel Exploitation
Practical Windows Kernel Exploitation
 

More from GameLandVN

Mobile Game Asia 2015 Ho Chi Minh City: Mobile games for Asian women
Mobile Game Asia 2015 Ho Chi Minh City: Mobile games for Asian womenMobile Game Asia 2015 Ho Chi Minh City: Mobile games for Asian women
Mobile Game Asia 2015 Ho Chi Minh City: Mobile games for Asian women
GameLandVN
 
Mobile Game Asia 2015 Ho Chi Minh City: Vietnam online mobile game market ins...
Mobile Game Asia 2015 Ho Chi Minh City: Vietnam online mobile game market ins...Mobile Game Asia 2015 Ho Chi Minh City: Vietnam online mobile game market ins...
Mobile Game Asia 2015 Ho Chi Minh City: Vietnam online mobile game market ins...
GameLandVN
 
Mobile Game Asia 2015 Ho Chi Minh City: Mobile game market in India
Mobile Game Asia 2015 Ho Chi Minh City: Mobile game market in IndiaMobile Game Asia 2015 Ho Chi Minh City: Mobile game market in India
Mobile Game Asia 2015 Ho Chi Minh City: Mobile game market in India
GameLandVN
 
Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...
Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...
Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...
GameLandVN
 
Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...
Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...
Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...
GameLandVN
 
Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...
Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...
Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...
GameLandVN
 
Mobile Game Asia 2015 Ho Chi Minh City: Rewarded video ads
Mobile Game Asia 2015 Ho Chi Minh City: Rewarded video adsMobile Game Asia 2015 Ho Chi Minh City: Rewarded video ads
Mobile Game Asia 2015 Ho Chi Minh City: Rewarded video ads
GameLandVN
 
Mobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in Vietnam
Mobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in VietnamMobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in Vietnam
Mobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in Vietnam
GameLandVN
 
Mobile Game Asia 2015 Ho Chi Minh City: Predictive monetization
Mobile Game Asia 2015 Ho Chi Minh City: Predictive monetizationMobile Game Asia 2015 Ho Chi Minh City: Predictive monetization
Mobile Game Asia 2015 Ho Chi Minh City: Predictive monetization
GameLandVN
 
Mobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creation
Mobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creationMobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creation
Mobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creation
GameLandVN
 
Cloud Powered Mobile Apps with Azure
Cloud Powered Mobile Apps with AzureCloud Powered Mobile Apps with Azure
Cloud Powered Mobile Apps with Azure
GameLandVN
 
Windows app & Microsoft's support
Windows app & Microsoft's supportWindows app & Microsoft's support
Windows app & Microsoft's support
GameLandVN
 
Kinh nghiệm phát triển Captain Strike
Kinh nghiệm phát triển Captain StrikeKinh nghiệm phát triển Captain Strike
Kinh nghiệm phát triển Captain Strike
GameLandVN
 
Microsoft BizSpark
Microsoft BizSparkMicrosoft BizSpark
Microsoft BizSpark
GameLandVN
 
Microsoft Azure Introduction
Microsoft Azure IntroductionMicrosoft Azure Introduction
Microsoft Azure Introduction
GameLandVN
 
OGDC 2014: Animation workflow with Spine in Tiny Busters
OGDC 2014: Animation workflow with Spine in Tiny BustersOGDC 2014: Animation workflow with Spine in Tiny Busters
OGDC 2014: Animation workflow with Spine in Tiny Busters
GameLandVN
 
OGDC 2014: Vietnam Smartphone game market 2013 overview
OGDC 2014: Vietnam Smartphone game market 2013 overviewOGDC 2014: Vietnam Smartphone game market 2013 overview
OGDC 2014: Vietnam Smartphone game market 2013 overview
GameLandVN
 
OGDC 2014: Speed up and make quality for your 3d models
OGDC 2014: Speed up and make quality for your 3d modelsOGDC 2014: Speed up and make quality for your 3d models
OGDC 2014: Speed up and make quality for your 3d models
GameLandVN
 
OGDC 2014: One-Man Studio: How to make a game prototype
OGDC 2014: One-Man Studio: How to make a game prototypeOGDC 2014: One-Man Studio: How to make a game prototype
OGDC 2014: One-Man Studio: How to make a game prototype
GameLandVN
 
OGDC 2014: Community building in Dragon Island
OGDC 2014: Community building in Dragon IslandOGDC 2014: Community building in Dragon Island
OGDC 2014: Community building in Dragon Island
GameLandVN
 

More from GameLandVN (20)

Mobile Game Asia 2015 Ho Chi Minh City: Mobile games for Asian women
Mobile Game Asia 2015 Ho Chi Minh City: Mobile games for Asian womenMobile Game Asia 2015 Ho Chi Minh City: Mobile games for Asian women
Mobile Game Asia 2015 Ho Chi Minh City: Mobile games for Asian women
 
Mobile Game Asia 2015 Ho Chi Minh City: Vietnam online mobile game market ins...
Mobile Game Asia 2015 Ho Chi Minh City: Vietnam online mobile game market ins...Mobile Game Asia 2015 Ho Chi Minh City: Vietnam online mobile game market ins...
Mobile Game Asia 2015 Ho Chi Minh City: Vietnam online mobile game market ins...
 
Mobile Game Asia 2015 Ho Chi Minh City: Mobile game market in India
Mobile Game Asia 2015 Ho Chi Minh City: Mobile game market in IndiaMobile Game Asia 2015 Ho Chi Minh City: Mobile game market in India
Mobile Game Asia 2015 Ho Chi Minh City: Mobile game market in India
 
Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...
Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...
Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...
 
Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...
Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...
Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...
 
Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...
Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...
Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...
 
Mobile Game Asia 2015 Ho Chi Minh City: Rewarded video ads
Mobile Game Asia 2015 Ho Chi Minh City: Rewarded video adsMobile Game Asia 2015 Ho Chi Minh City: Rewarded video ads
Mobile Game Asia 2015 Ho Chi Minh City: Rewarded video ads
 
Mobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in Vietnam
Mobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in VietnamMobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in Vietnam
Mobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in Vietnam
 
Mobile Game Asia 2015 Ho Chi Minh City: Predictive monetization
Mobile Game Asia 2015 Ho Chi Minh City: Predictive monetizationMobile Game Asia 2015 Ho Chi Minh City: Predictive monetization
Mobile Game Asia 2015 Ho Chi Minh City: Predictive monetization
 
Mobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creation
Mobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creationMobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creation
Mobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creation
 
Cloud Powered Mobile Apps with Azure
Cloud Powered Mobile Apps with AzureCloud Powered Mobile Apps with Azure
Cloud Powered Mobile Apps with Azure
 
Windows app & Microsoft's support
Windows app & Microsoft's supportWindows app & Microsoft's support
Windows app & Microsoft's support
 
Kinh nghiệm phát triển Captain Strike
Kinh nghiệm phát triển Captain StrikeKinh nghiệm phát triển Captain Strike
Kinh nghiệm phát triển Captain Strike
 
Microsoft BizSpark
Microsoft BizSparkMicrosoft BizSpark
Microsoft BizSpark
 
Microsoft Azure Introduction
Microsoft Azure IntroductionMicrosoft Azure Introduction
Microsoft Azure Introduction
 
OGDC 2014: Animation workflow with Spine in Tiny Busters
OGDC 2014: Animation workflow with Spine in Tiny BustersOGDC 2014: Animation workflow with Spine in Tiny Busters
OGDC 2014: Animation workflow with Spine in Tiny Busters
 
OGDC 2014: Vietnam Smartphone game market 2013 overview
OGDC 2014: Vietnam Smartphone game market 2013 overviewOGDC 2014: Vietnam Smartphone game market 2013 overview
OGDC 2014: Vietnam Smartphone game market 2013 overview
 
OGDC 2014: Speed up and make quality for your 3d models
OGDC 2014: Speed up and make quality for your 3d modelsOGDC 2014: Speed up and make quality for your 3d models
OGDC 2014: Speed up and make quality for your 3d models
 
OGDC 2014: One-Man Studio: How to make a game prototype
OGDC 2014: One-Man Studio: How to make a game prototypeOGDC 2014: One-Man Studio: How to make a game prototype
OGDC 2014: One-Man Studio: How to make a game prototype
 
OGDC 2014: Community building in Dragon Island
OGDC 2014: Community building in Dragon IslandOGDC 2014: Community building in Dragon Island
OGDC 2014: Community building in Dragon Island
 

OGDC 2014: Architecting Games in Unity

  • 1.
  • 2. Architecting Games in Unity Common patterns for developing games in Unity
  • 3. If this was your house, what would you do?
  • 4. Broken Windows •Fix the windows. •In New York City, Albuquerque and The Netherlands, improving the physical appearance of a neighbourhood has been shown to reduce crime and increase quality of life. •People are influenced by their environment: • Social norms and conformity • Routine monitoring
  • 5. Ah, Freedom! •Unity gives you a rich set of building blocks that can be used to construct any type of game. •Unity is flexible. •There are hundreds of ways to build projects. •And developers use ALL of them!
  • 6. Architecture for Games •But let's look at what you need •And let's create a structure that can be reused for efficiency and robustness
  • 7. Good Architecture = Good Standards •Use C# •Naming conventions • Use descriptive names • Use standardized capitalization • In Unity don’t be afraid of using spaces in names •Logical folder structure •Zero-tolerance for warnings and errors •Zero-tolerance for runtime memory allocation
  • 8. Core Application Logic •Main Controller • Base controller to manage high level application • Uses public static methods so everyone can access it • Uses Object.DontDestroyOnLoad so it is available throughout the project •Scenes • Other scenes are loaded on top of this. • MainController loads and unloads other scenes and cleans up.
  • 9. Main Controller – Reset State •Call GC.Collect to try to reclaim some memory.
  • 10. Main Controller – Preload State •Start loading the level asynchronously and change state to Load
  • 11. Main Controller – Load State •Keep going until loading is done
  • 12. Main Controller – Unload State •Resources.UnloadUnusedAssets() •Keep going until Unloading is done
  • 13. Main Controller – Postload State •Do things immediately after loading •Update currentSceneName
  • 14. Main Controller – Ready State •Call GC.Collect to try to reclaim some memory. • Avoid this if you have unused assets in the scene that may be used later. •Do things just before beginning: e.g.: Get User Input to Start
  • 15. Main Controller – Run State •We stay here until currentLevelName != nextLevelName •This can be changed by calling SwitchScene static public method on the Main Controller from anywhere
  • 16. Scene State Machine Implementation •We can use a switch-case • Gets difficult to maintain and read •We can use delegates • Unfortunately, setting a delegate allocates memory •So we use an array of delegates.
  • 17. Scene State Machine Implementation •Example Implementation • MainController, MenuController and GameController • Let’s look at the Profiler too!
  • 18. Implementing Gameplay •Controllers manage the objects •Inter-object communication • Static public methods • Temporary public instance methods • Messages, events •Most common are: • Singletons • “Pool” controllers
  • 19. Singleton •Only one of them in the game •Static public methods •Examples: • Score • Player • World • Game
  • 21. Pool Based Objects •Numerous instances in the game •Limited number at any one time •Preload simultaneously used quantity and disable •Static public method to “spawn” one finds first disabled one and enables it •Examples: • Explosions • Bullets • Enemies • Scenery
  • 22. GameObjects are loaded from storage and placed in a pool and disabled. Object Pool Storage Pool Based Objects
  • 23. GameObjects are activated when needed. Object Pool Storage Pool Based Objects
  • 24. GameObjects are deactivated when no longer needed. This returns them to the pool. Object Pool Storage Pool Based Objects
  • 26. Download •Find the Template.zip here: http://goo.gl/8WZGxn
  • 27. Best-Practices •Use C# •Naming conventions •Logical folder structure •Zero-tolerance for warnings and errors •Zero-tolerance for runtime memory allocation
  • 28. Thank You! Rustum Scammell Email: rus@unity3d.com Skype: rustumscammell