How to Program in Unity: Observer Pattern Explained

preview_player
Показать описание
Learn the fundamentals of the Observer Pattern in this new video break down and create a dynamic narration system just like in the game "Bastion" by SuperGiant Games!

This tutorial will teach you how to program and design systems in unity that communicate seamlessly while remaining easy to debug, scale, and maintain. Learn the power of decoupled code and elevate your game development skills to the next level!

This is a new episode in a growing series on this channel: Programming for Production. In this series, we take relatively complex software development topics and try to explain them in easy-to-understand ways. Let's take our programming skills to the next level!

ACCESS PROJECT FILES & SUPPORT THE CHANNEL:

WANT MORE?
Interested in learning more about animating characters in Unity? Check out my growing series of tutorials:
✦ Like the vid? Please consider Subscribing!
✦ Missed out on the last episode?

SOCIAL:
✦ Discord
✦ Twitter

►TIMESTAMPS:
0:00 Intro
0:49 The Problem and Solution
1:24 Coupled Code Explained
1:52 Pseudocode Example
3:43 The Observer Pattern
5:00 Implementing the Observer Pattern
7:58 Bastion Narration System
13:45 Handling Multiple Actions
14:17 Final Result
14:52 Outro

Thank you for stopping by and checking out my tutorial -- Hope you all enjoy! Please feel free to leave any questions & feedback you may have. This will help shape the direction and style for upcoming videos!

Thanks again for watching!

#indiegame #gamedev #indiedev #2023
Рекомендации по теме
Комментарии
Автор

✨ Before C# and UnityEvents there was… THE OBSERVER PATTERN! ✨ Let’s level-up our programming skills and break down another design pattern to create an awesome gameplay feature and gain an understanding of how these built-in event systems were created! I also have to say that as an avid fan of both Bastion and SuperGiant Games, this new video has been an absolute blast to make! I hope you all love it too!


Smash that like button if you can't wait to learn!

Cheers!🍻
-Nicky

iHeartGameDev
Автор

Thank you for previewing the end goal idea. It drives me crazy how many videos/tutorials are out there that don't show the end result at the beginning, it is what hooks me in!

chris.davidoff
Автор

Great stuff! However, small note: there's no need to implement the observer pattern in Unity since C# Actions exist. The observer pattern was made for non-event driven languages like C++.
You can even put an Action in an interface. I'd do that and use [SerializeReference] on a list of the subject interface with maybe a custom property drawer.
That way your class doesn't have to inherit from a subject class either.

Mood
Автор

I wanna see the advanced narration system at some point in the future

pitchblack
Автор

Thing of note, as hinted in the pinned comment, is that C# provides this functionality with its Events(not Unity Events).So if one sticks with C# they can use C# events instead of making their own implementation.
I understand that this video may be made for any language user that doesnt have events like C# but thought i'd let people know.

ZeroSleap
Автор

I would say that the method you've explained here is still kind of coupled, since it requires a direct reference to all of the subjects that need to be notified. If you were to delete one of the subjects from the scene, it would end up causing an error. Plus, this is not scalable for games that rely on a multi-scene architecture.
However, this was a great introduction to the topic! I'm sure you'll get into more details in future tutorials. Speaking for myself, I am a huge fan of the ScriptableObject based event pattern.

Keep up the good work! I love your channel and the way you lay out your videos to explain the topics you cover in a highly-detailed and beginner-friendly way.

gabaguiarp
Автор

i like how you cover multiple subject in just one video, one can learn a lot of things from it, Basic Audio Handling, Observer Pattern, Enums etc in one video that's amazing ngl

KousseilaMd
Автор

Subscribed! This was GREAT... probably the finest tutorial I've watched on a programming pattern. Not too fast, not too slow, not too heavy on theory. Would LOVE an advanced tutorial, as well as more videos on other patterns. Looking forward to everything you do!

ZebulonsPi
Автор

This is some of the most calibrated and well explained content I've seen on the subject in a long time.

everlastingmedia
Автор

I wanted to take my take to say out loud how much I do appreciate your work in your channel. As you may have heard before, its not only how good are the subjects and professionalism in the production of the content, but even more fundamentally the way of explaining things. The way that you code things and later change it for a more optimazed way explaining why and how it works. I could write pages about how great in general your channel is and the amount of things and abstract concepts I have learned thanks to you. The best of luck, keep the good work and the energy!

SolFuture
Автор

Finally! I've been searching for not just an explanation but an implemenation. Great video!

emilsitell
Автор

Can't wait for this one. I found your channel 2 days ago, and this is the most valuable Unity channel I have ever seen. I'm glad you explain everything in an easy way. Please keep it going. I hope, you gonna get more subscribers soon.

FoXcodeZ
Автор

My code isn’t merely coupled, its polygamously married to everything and even death doesn’t part them.
This was far easier to follow than Microsoft’s documentation. Many thanks.

paulaembleton
Автор

Thanks again for turning abstract gaming patterns into real examples. You are amazing!

gamemacher
Автор

best game dev tutorial channel I've ever watched. Thank u so much for giving me easy-to-understand content and your easy-to-hear voice

khicontocvang
Автор

Great video as always. I recently participated in a game jam and in 48 hours I made a mess of my game folders and did a lot of coupled code. You exactly targeted the problems I saw and provided the cleanest solution. I'm definitely gonna implement this in my next game jams and have a peaceful life adding features <3. Thanks a lot.

tamilmaran
Автор

Man... The observer pattern explanation is top notch!

JeshG
Автор

The advanced system is exactly what there need to be more of.
Nice, clear tutorial. Thanks.

puntalic
Автор

The observer pattern is a nightmare in a large codebase. If you have multiple devs with varying levels of skill over a period of years this will turn into the worst spaghetti mess you've ever seen. In my day job I work on an application with 600k+ lines of code. We have this pattern and while it does decouple things it easier to introduce bugs, harder to debug, difficult to schedule operations and easier to accidentally do work more than once.

Just remember: coupling isn't always bad.

Hector-bjls
Автор

Your animation tutorial is insane! I really enjoy your emotionality and how you explain difficult things in plain language! Thanks for your work!
From Russia with love

hpzero
welcome to shbcf.ru