Programming design patterns: E-book and sample project for Unity users

Hello everyone!

My name’s Thomas and I lead the technical content team in Copenhagen. We create intermediate-to-advanced content for programmers, artists, technical artists, and designers developing games and other applications with Unity. You might have seen some of our posts, like the QuizU UI Toolkit series on Discussions, or downloaded a few of the e-books we’ve published. You might also have seen some of our demo projects on Github or the Asset Store.

A request we have seen a lot (over the years) is more guidance on how to leverage common object-oriented programming practices, namely SOLID principles and design patterns in the context of Unity. So in this post we wanted to link to our content about implementing programming design patterns in your Unity projects.

When working in Unity, you don’t have to reinvent the wheel. It’s likely someone has already invented one for you. For every software design issue you encounter, a thousand developers have been there before. While you can’t always ask them directly for advice, you can learn from their decisions through design patterns.

Design patterns are general solutions to common problems found in software engineering. These aren’t finished solutions you can copy and paste into your code, but extra tools that can help you build larger, scalable applications when used correctly.

By integrating patterns consistently into your project, you can improve code readability and make your codebase cleaner. Design patterns not only reduce refactoring and the time spent testing, they can speed up onboarding and development processes.

Here’s our recommended reading list if you are interested in learning about them in the context of Unity game development:

  1. The e-book: Level up your code with game programming patterns



    This free 98-page e-book explains some of the most well-known and commonly used design patterns for Unity. The e-book also includes practical examples for how you can use them in your Unity project. Here are some of the topics we cover in the guide:

    • SOLID principles
    • General software development principles like KISS and DRY
    • Design patterns for game development
    • Model View Presenter (MVP), Factory, singleton, command, state, observer patterns and object pooling
  2. The how-to articles for each design pattern

    We go even more in-depth with each design pattern in this series of articles, adding more details and tips for how to implement them in a Unity project. The pages are:

    Create modular and maintainable code with the observer pattern
    Use object pooling to boost performance of C# scripts
    Develop a modular and flexible code base with the state pattern
    Use the factory pattern for object creation at runtime
    Build a modular codebase with MVC and MVP programming patterns
    Use the command pattern for flexible and extensible game systems

  3. The Design Patterns demo project

    This GitHub repository contains bite-sized Unity scenes that you can use to see the design patterns in action. Use it to follow along while reading the articles or e-book at your own pace.

UI and programming design patterns in a sample project

A closely related project to the programming design patterns e-book is the QuizU UI Toolkit sample we recently released. QuizU is a sample of an interactive quiz application that shows how UI Toolkit components can work together, leveraging various design patterns, in a small but functional game, complete with multiple screens and game flow management. So while the project is about UI it’s a very programmer-centric demo which is also about how you wire up your code with UI in a way that scales for larger productions. Similarly, we explain UI Toolkit concepts and tools from a developer’s perspective, rather than an artist’s.

Check out our QuizU articles on Discussions to learn more and download the project from the Asset Store (recommended Unity version is 2022 LTS).

A series of advanced resources for all Unity programmers

The programming design patterns guide is one in a series of resources we created for experienced Unity programmers. The other e-books in the series are:

  1. Create a C# style guide: Write cleaner code that scales
  2. Create modular architecture in Unity with ScriptableObjects

You can find all the e-books (and many how-to articles) in the Unity best practices hub or via the best practices page in Unity documentation.

Let us know if any of these resources are helpful. We really appreciate it and use your feedback to both update existing but also plan future learning resources.

1 Like