The 6 Design Patterns game devs need?

preview_player
Показать описание

We'll talk about which design patterns game programmers use, what design patterns are... and why you should care about them. I'll also show you how to implement each pattern in unity using some simple code and examples.

0:00 - Intro
1:11 - Beg for Likes
1:28 - Singleton Pattern
4:55 - Observer Pattern
9:52 - Command Pattern
16:32 - Component Pattern
17:41 - Flyweight Pattern
21:15 - State Pattern
22:35 - 100's of design patterns? (wrap-up and discussion)

Рекомендации по теме
Комментарии
Автор

Don't forget the Refractory pattern: you watch a video on patterns and you go refactor all your code.

bigedwerd
Автор

I went to college and got a Bachelor's Degree in Computer Science, and the only pattern they talked about on this list was the Singleton pattern.
I feel horribly cheated.
Love your work, man!

patricksmith
Автор

This video should definitely be watched by anyone who´s starting out on game development, I could´ve spared so much time if only a video like this existed a couple years back. Great video! This video deserves all the likes!

dalvandi
Автор

Thanks for this! I'm a senior C# developer but most of my knowledge of patterns comes from developing Mobile/Desktop/Web apps.
Knowing more about how to implement some of this patterns (some are used in my industry) helps me a lot to get my head around game dev (which is one of my childhood dreams).
One small comment to keep in mind, on 8:46 the question mark is actually not related to the events. Its just an operator used to do inline null checks prior to running any method (actually called "null conditional operator").
Basically it saves you from writing something like:
if(event != null)
event.Invoke();
You can also use it to get values from possible null reference objects:
if(nullableObject?.Property == 1)
instead of
if (nullableObject != null && nullableObject.Property == 1)
Sorry for the nerdy post.
Once again. Great video and thank you for taking the time to explain this!

JuanuHaedo
Автор

This video randomly showed up in my feed. I'm glad it did. It's really nice to see design patterns being put to use together with Unity and explained very well. A lot of Unity resources out there teaches a lot of bad habits. Keep up the good work :-)

MKayJay
Автор

I just implemented the command patern in my game to create a cinematic camera motion effect on demand. Coupled it with an event system for easier calling and avoiding having anything on update and I must say, it works great. Also swapped out Queue for List for easier manipulation (inserting preset commands when and where i need them).
Thanx for the informative video Jason. Keep up the good work.

relinqushed
Автор

For anyone that wants to learn more design patterns: the Gang of 4 design patterns book is something to look at

But really, the patterns this person is listing are actually pretty useful- courses tend to just cover a handful of design patterns and these were indeed some of the big ones we went over in my curriculum

MrJellyconelly
Автор

Design patterns are really important, but many game devs ignore them and say that OOP for Unity is bad, that it is built to be used in more data-driven component-driven way. I appreciate videos about design patterns in Unity. I hope you will make another one in the future. It's really important for the Unity community and I thank you so much.
I want to mention 1 more incredibly useful design pattern: Decorator. It's amazing for creating different "children" without inheritance and it helps you to follow the Single Responsibility and Open-Closed principles from SOLID. I can give a short example: you have a weapon decorator, then you want to have different types of weapon - you use the decorator to create concrete decorated weapon classes. For example you can share the same method Attack but you can modify the behavior of the Attack in every concrete decorated variant, or you can have entirely different methods and behaviors (but you can still share whole methods/behaviors between classes). It kinda makes your life harder with the Liskov's rule from SOLID, but you can still group "categories" of weapons via interfaces like IMeleeWeapon, IRangedWeapon and you can still have methods with parameter of type interface so you can pass different concrete decorated implementations in the same method (parameter).
So it's really good pattern. Very useful for game dev. Especially if you already have a good Sword class (which is a concrete implementation of the WeaponDecorator) and it's perfectly working (and tested if you do Unit Tests), and you don't want to mess around this perfectly working class - you can decorate the decorated class again so you "extend it" with more logic, which could be not so perfect and tested logic, but it won't mess up with the base sword class. This is the Open-Closed rule - you must extend classes, instead of modifying them. This is really useful in game dev because we as devs have a crapton of ideas in our heads and we sometimes fuck up really good classes with extra gameplay and logic and then we can't "rollback" the class to its older version, because we don't want to lose the new logic. With Decorator you can "fix" your new logic without losing the old logic (while using the old logic).

You can also make easier patches/updates to your game this way. For example your game is perfectly working, you want to add more gameplay. It's safer to add the new gameplay in decorated implementations, because the game will be perfectly fine while using the old logic. This way you can implement the new behavior only for your DLC for example. It's like an really old website and you start updating it to version 2.0. You decorate the old classes and slowly replace the old stuff with new stuff. If you directly change the old logic, you will not be able to return the website in a good working condition with the new features.

Abken.
Автор

I really love your videos, and I'm especially grateful for topics like this where you take an almost academic approach to game dev as it relates to core dev principals.
Design patterns are a bit of a blessing and a curse for me. I love having this array of simple, well-tested, and generalized solutions to common problems from which to draw from. My main problem with design patterns is in recognizing when I'm faced with a problem for which there is already a pattern. Maybe run this past your other subscribers, cause I'm sure I'm not the only one, but I'd really love it if you did deep dives of as many use cases for each pattern as possible.

bibulousape
Автор

Hi Jason! I have an exam in a few weeks regarding some of the patterns you just showed. Really appriciate that you have taken your time and explained them in a very easy way. Great video!

Chris-xexr
Автор

I watched this about 3 months ago, and now use almost every single one of these patterns in the game I'm working on right now, thanks for making this!

ndev
Автор

These are the best Unity videos on the web. Thank you so much for your hard work. The explanations are concise with great examples, but not in-depth enough that the viewer doesn't have to do their own work to understand the concepts more deeply (which is a good thing).

kstrouse
Автор

perfect video for me right now. I like your teaching and explaining style. You go more into details than other ppl and also add real life examples from your own experience and it makes complete picture.

pa
Автор

Great video! The explanations were well thought out and clear to understand. Hope to have more programming videos since you're really good at teaching them. Thanks a bunch!

Babush
Автор

Thanks, Jason. That's a super helpful introduction to design patterns! Definitely something a lot more starting game dev could use

lukavelinov
Автор

This is a great explanation of patterns and examples of each. Thanks for sharing your knowledge Jason.

SuperDutchrutter
Автор

As a mobile and web developer who enter the game dev about a year ago, it's really nice to see content like this.
I was used to these architectures and design patterns before and until now, Unity community seemed kinda messier with this topic. I even wrote some patterns to help me out in this transition. Definitely gonna read and test some of those!

Mikabrytu
Автор

Hey Jason, dropping by to say it's good to see a new video from you! Hope you and your family are well.

justinhhorner
Автор

This has been a super helpful video, both for my hobby as a game developer and for my job as a software developer! Thank you for making these videos!

crabdog
Автор

I really like that Command pattern. I need to remember that one, particularly.

clamum