Cover....1
Title page....2
Copyright and credits....3
Dedication....4
Foreword....5
Contributors....6
Table of Contents....8
Preface....12
Part 1: Learning from Unreal Engine 5....18
Chapter 1: Understanding Unreal Engine 5 and its Layers....20
Technical requirements....20
Introducing Unreal Engine 5....21
Installing Unreal Engine 5 and preparing your development environment....22
The Fuzzy layer – bridging the gap from C to Blueprint....25
Property Specifiers....27
Function Specifiers....28
Useful inheritance....28
Translating back from Blueprint to C....30
Worked example....32
Summary....35
Questions....35
Answers....36
Chapter 2: Hello Patterns....38
Technical requirements....38
S.O.L.I.D. principles....39
Single responsibility....40
Open-closed....40
Liskov substitution....42
Interface segregation....44
Dependency inversion....46
Exploring solutions to common problems....47
The moving box problem....48
The rotating box problem....56
The cascading cast chain problem....59
The trade-off....63
Summary....64
Chapter 3: UE5 Patterns in Action – Double Buffer, Flyweight, and Spatial Partitioning....66
Technical requirements....66
Double buffer....67
Flyweight....70
Spatial partitioning....72
Introducing World Partition....74
Understanding when objects are loaded....78
Ensuring actors are loaded when required....80
Enabling World Partition on an existing level....82
Summary....82
Chapter 4: Premade Patterns in UE5 – Component, Update Method, and Behavior Tree....84
Technical requirements....84
Understanding and creating components....85
Applying the update method for prototyping gameplay....91
Working with behavior trees....93
Creating the AI controller....95
Creating the Blackboard asset....97
Building the behavior tree....98
Summary....113
Part 2: Anonymous Modular Design....114
Chapter 5: Forgetting Tick....116
Technical requirements....116
Before we begin....117
A world that ticks....117
A clock that stops....120
Event driven systems....125
Summary....128
Chapter 6: Clean Communication – Interface and Event Observer Patterns....130
Technical requirements....130
Interfacing communication across classes in UE5....131
Blueprint interfaces....131
Interface events versus functions....135
Interfaces in C....137
Building an example interface communication....139
Implementing event delegate communication across UE5....140
Event delegates in Blueprint....140
Event delegates in C....144
Building a useful delegate tool....146
Summary....149
Chapter 7: A Perfectly Decoupled System....150
Technical requirements....150
Using UML to plan a sample hierarchy....151
What are the types of class relations?....151
What is a sequence diagram?....153
Decoupling the reference train....154
Modularity and decoupling....154
Establishing infrastructure....157
Implementing decoupled design in an example....158
Benefits of decoupling....169
Summary....169
Part 3: Building on Top of Unreal....170
Chapter 8: Building Design Patterns – Singleton, Command, and State....172
Technical requirements....172
Implementing a Singleton pattern – understanding why its a Pandoras box....173
Implementing the Command pattern for different use cases....175
Command pattern for undo functionality in Blueprint Utilities....177
Command pattern for gameplay in C....180
Creating the many levels of a state machine....183
Exploring animation state machines....184
Enumswitch implementation....186
Static versus instanced states....188
Concurrent state machines....190
Hierarchical state machines....191
Pushdown automata....192
Summary....193
Chapter 9: Structuring Code with Behavioral Patterns –Template, Subclass Sandbox, and Type Object....194
Technical requirements....195
Exploring the template pattern....195
Building the template (parent class)....196
Creating child classes....198
Template pistol....200
Template shotgun....205
Understanding subclass sandbox....206
Building the sandbox (parent class)....207
Creating child classes....210
Sandbox pistol....210
Sandbox shotgun....213
Type object pattern....214
Variants....215
Data Tables....217
Data Assets....217
Summary....221
Chapter 10: Optimization through Patterns....222
Technical requirements....223
Using dirty flags to reduce unnecessary processing....223
Application of dirty flags....224
How data locality affects code efficiency....225
Hotcold splitting....226
Contiguous arrays....226
Object pooling our resources to save time later....227
Implementing object pooling....228
Making an object pool....229
Summary....241
Index....242
Other Books You May Enjoy....249
Improve your game's code with design patterns to make it more readable, reusable, modular, and optimized, guided by an Unreal Authorized Instructor to enhance your overall use of C++ with Unreal Engine
Design patterns serve as a toolkit of techniques and practices that enable you to write code that’s not only faster, but also more manageable. With this book, you’ll explore a range of design patterns and learn how to apply them to projects developed in Unreal Engine 5.
You’ll begin by delving into the foundational principles of coding and develop a solid understanding of the concepts, challenges, and benefits of using patterns in your code. As you progress, you’ll identify patterns that are woven into the core of Unreal Engine 5 such as Double Buffer, Flyweight, and Spatial Partitioning, followed by some of the existing tool sets that embody patterns in their design and usage including Component, Behavior Tree, and Update.
In the next section of the book, you’ll start developing a series of gameplay use cases in C++ to implement a variety of design patterns such as Interface and Event-based Observers to build a decoupled communications hierarchy. You’ll also work with Singleton, Command, and State, along with Behavioral Patterns, Template, Subclass Sandbox, and Type Object. The final section focuses on using design patterns for optimization, covering Dirty Flag, Data Locality, and Object Pooling.
By the end, you’ll be proficient in designing systems with the perfect C++/Blueprint blend for maintainable and scalable systems.
If you are a beginner or intermediate game developer working with Unreal Engine and looking to improve your C++ coding practices, this book is tailor-made to help you produce clean, reusable code through the application of design patterns.
While this book will cover introductory tasks to show the fundamentals of Unreal Engine 5, its primary purpose is not to teach Unreal Engine from scratch. Prior experience with Unreal Engine will be beneficial, but don’t fret if your knowledge isn’t in-depth; the book will introduce tools and features as needed.