How to Program in Unity: Observer Pattern Explained

  Рет қаралды 117,694

iHeartGameDev

iHeartGameDev

Күн бұрын

Пікірлер
@iHeartGameDev
@iHeartGameDev Жыл бұрын
✨ 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! The project files for anyone who wants to get hands on the project without building the whole thing yourself: www.patreon.com/posts/project-files-to-77632739 Smash that like button if you can't wait to learn! Cheers!🍻 -Nicky
@artistaartificial5635
@artistaartificial5635 Жыл бұрын
I have another complex solution: GPT-3 + VALL-E or another Text2Voice AI. GPT-3 generate a text when the observer notify sending a prompt to GPT-3 and VALL-E generate the audio.
@chris.davidoff
@chris.davidoff Жыл бұрын
@@artistaartificial5635 Killer idea :P
@ZeroSleap
@ZeroSleap Жыл бұрын
​@@artistaartificial5635 A probably incredibly inefficient idea because you are introducing 1.A dependency on the GPT service and you dont really know the outcome,and 2. A slow response time cause we talking about an AI calculating a response and receiving it.
@chris.davidoff
@chris.davidoff Жыл бұрын
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!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thanks for watching Chris! Good to know that sharing the preview is a good idea at the start!
@pitchblack5422
@pitchblack5422 Жыл бұрын
I wanna see the advanced narration system at some point in the future
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you for the support, Pitch Black!
@anupamkumar4109
@anupamkumar4109 Жыл бұрын
Me too
@thiagofloreste9114
@thiagofloreste9114 Жыл бұрын
same!
@soul_avc4691
@soul_avc4691 Жыл бұрын
DEFINITELY!!!!
@amdretm
@amdretm Жыл бұрын
Me too!
@mody1710
@mody1710 Жыл бұрын
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.
@somerandomchannel382
@somerandomchannel382 Жыл бұрын
show code Examples
@EvgeniPetrov
@EvgeniPetrov Жыл бұрын
UnityEvent is even more powerful as it gives ability to hook them up inside the editor
@johnandbuddy
@johnandbuddy Жыл бұрын
Hey, would you mind elaborating on this, or giving me a search term that I could use to find more info, I tried searching C# actions, Unity C# Actions, Why Observer Pattern is not needed in c#, and I got some info, but still am not super clear on it. Thanks
@EvgeniPetrov
@EvgeniPetrov Жыл бұрын
@@johnandbuddy Not sure if this comment is targeted at me. UnityEvent has enough info on the net.
@johnandbuddy
@johnandbuddy Жыл бұрын
@@EvgeniPetrov hey thanks for the reply, no I was asking the op of the comment. But I have since learned about unityEvent and love it. I was more asking what was the commenter talking about with Actions.
@KousseilaMd
@KousseilaMd 10 ай бұрын
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
@iHeartGameDev
@iHeartGameDev 10 ай бұрын
Thanks so much!!!
@ZeroSleap
@ZeroSleap Жыл бұрын
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.
@ilonachan
@ilonachan Жыл бұрын
also, not really relevant to Unity, but Godot's own language GDScript also has first-class support for Signals, and I imagine it works very similarly.
@gabaguiarp
@gabaguiarp Жыл бұрын
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.
@ZebulonsPi
@ZebulonsPi Жыл бұрын
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!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you so much for the kindness, Jason!!
@SolFuture
@SolFuture Жыл бұрын
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!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Hey Jose! Those kind words mean a lot. It's super reassuring to read that the time and effort I put into each video is actually worth it. It's been a while since this last upload, but I'm hoping that the next video I release can match the quality!
@Jesh31G
@Jesh31G Жыл бұрын
Man... The observer pattern explanation is top notch!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thanks so much Jesh! :) I tried to make it as beginner friendly as possible
@FoXcodeZ
@FoXcodeZ Жыл бұрын
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.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you, Kitsune! I’m glad you’ve enjoyed my videos and I hope they have helped you out on your gamedev journey! 😊
@Agent-Spear
@Agent-Spear Жыл бұрын
same I just found this channel and it's tutorials are phenomenal!
@PauloHSousa237
@PauloHSousa237 Жыл бұрын
This one ir the best unity Chanels. Hi from Brazil
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you so much Paulo! I hope you like this new video :)
@PauloHSousa237
@PauloHSousa237 Жыл бұрын
@@iHeartGameDev my english is not that bad. I was running on the treadmill
@gamemacher87
@gamemacher87 Жыл бұрын
Thanks again for turning abstract gaming patterns into real examples. You are amazing!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
That is the goal! Thank you for the kindness!
@everlastingmedia
@everlastingmedia Жыл бұрын
This is some of the most calibrated and well explained content I've seen on the subject in a long time.
@RodrigoP3ssoal
@RodrigoP3ssoal 3 ай бұрын
I would absolutely love to see the part two, advanced, of this video! What I struggle the most with my learning of game programming is definitely code organization and maintenance having in mind scalability, readability and how components and scripts talk to each other. Think video was very cool regarding that, I feel like I need to watch it a couple times to fully grasp it and give it a try as well, but it was awesome! Thanks!
@emilsitell5484
@emilsitell5484 Жыл бұрын
Finally! I've been searching for not just an explanation but an implemenation. Great video!
@tamilmaran4000
@tamilmaran4000 Жыл бұрын
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
@Russellgamingstudios
@Russellgamingstudios Жыл бұрын
I’m currently making a Christian horror game thanks for all of your videos they helped me out
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Happy to help!
@khicontocvang
@khicontocvang Жыл бұрын
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
@ThanhNguyen-po7zy
@ThanhNguyen-po7zy Жыл бұрын
Thanks. Super nice explanation. I am exhausted of waiting the advanced observer Pattern.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you! I’ll get to the advanced version at some point!
@hpzero4207
@hpzero4207 Жыл бұрын
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
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you so much!
@chuckchuk14
@chuckchuk14 Жыл бұрын
Fantastic video, as always! You're the new GOAT for good game dev practices. Love your videos.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thanks so much Chuck!
@mlt_sk
@mlt_sk 2 ай бұрын
Good video To all the people asking "why not use x", I like to learn how things work, i wanna learn things that will make me not rely on a specific software with pre built stuff so that i can transfer the knowledge and experience to other situations.
@faridbehrouzi6228
@faridbehrouzi6228 Жыл бұрын
Best video about the observer pattern I found so far. Thanks a lot.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Wow, thanks! That's quite the compliment!!
@CollinPatrick
@CollinPatrick Жыл бұрын
In recent projects, I have adopted the use of scriptable object events that can be plugged into a variable in the inspector in the object that calls it (subject). I then have a seperate component that can listen to an event (Observer) and pass it along to anything subscribed to an exposed UnityEvent than can be populated in the inspector as well. This allowed our designers to create custom interactions based on different game states without ever having to touch the code.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
This sounds like an optimal implementation! Thank you for sharing!
@leosalazar9213
@leosalazar9213 Жыл бұрын
I have seen other vídeos about the topic but i feel this is the first and only time i could understand it xp
@puntalic
@puntalic Жыл бұрын
The advanced system is exactly what there need to be more of. Nice, clear tutorial. Thanks.
@rehrocks
@rehrocks Жыл бұрын
Ive Just pause the video to say, you are awesome, the way you show and solve the problem is perfect, thank you
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you so much, Redley!
@jacksoundwave2091
@jacksoundwave2091 Жыл бұрын
This channels deserves way more subscribers
@VladaPersonal
@VladaPersonal Жыл бұрын
A pretty nice overview indeed! I feel like knowing both how to allow observing multiple subjects and also how to have one subject to be observed for different reasons as the subject now has just one list of observers.
@NightStudios
@NightStudios Жыл бұрын
An amazing video, the dedication you put into it is admirable, the way you express yourself is unmatched. All your videos are educational and of a quality above what can be found in many universities.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you for such kind words! It truly means a lot!
@TheKr0ckeR
@TheKr0ckeR Жыл бұрын
I always wondered your way of handling Observer Pattern! That a great one. Thanks for your effort on this video. This is diamond.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you so much! This was a fun one to make!
@AbdullahGameDev
@AbdullahGameDev Жыл бұрын
Thanks so much. I was making a game and put all Observers in Subject 😅 and ask my self how to solve this and suddenly find your video Thanks to Observer Pattern my subject now is clean. Thanks Again👏.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Glad I could help!
@Departageance
@Departageance Жыл бұрын
That's really interesting. Thanks for this video. Multiple subjects would be a topic I'd like to see in your next video.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Sure thing! Thank you!
@dankodev
@dankodev Жыл бұрын
This is interesting! I've actually started using the observer pattern and loved it so much that I decided to drop the singleton pattern altogether. I've also recently discovered that Scriptable Objects can be used to implement this observer pattern and make super complex event systems that are even capable of passing values between objects!
@D.KRyley-mq1do
@D.KRyley-mq1do Ай бұрын
How are you doing this? My current system is using an event system using delegates that track variables on scriptable objects to trigger events. It works but I've only done small scale things with it and am wondering if there's something I'm missing
@paulembleton1733
@paulembleton1733 Жыл бұрын
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.
@danielruizleyva3825
@danielruizleyva3825 Жыл бұрын
Ill love to see the next part of this project. Excelente job!
@ShinStalk
@ShinStalk Жыл бұрын
Would gladly watch the continuation of this character’s adventure in the observers world
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Awesome thank you!
@GrahamOfLegend
@GrahamOfLegend Жыл бұрын
Excellent tutorial as always! Keep em coming please, you're def one of the best on KZbin 🙏🏽
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Graham! Thanks so much for the kind words, bro!
@Twelveoglock1
@Twelveoglock1 Жыл бұрын
This was amazing! Great video, would love to see you keep going.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you so much!
@postman428
@postman428 Жыл бұрын
I never knew i need this tutorial, So helpful, Thanks!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Happy to help!
@james7491
@james7491 Жыл бұрын
event Actions are also a great implementation of the observer pattern, I use them a lot for decoupling
@iHeartGameDev
@iHeartGameDev Жыл бұрын
They are! 😄
@travellerinthedark
@travellerinthedark Жыл бұрын
I loved this look at what seems to be the theory behind Events. I'd love to see more on this topic like you asked at the end. Also, I love Bastion and Supergiant games in general too.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
That was the intention! Now when people look into Unity Events they'll have a good understanding of the general concept and purpose.
@felfurion8624
@felfurion8624 Жыл бұрын
Great. Yes to the advanced tutorial on this topic would be welcome and I'll look forward to the procedural animation video.
@pratikdeshmukh7508
@pratikdeshmukh7508 Жыл бұрын
Great stuff dude. Your explanation is really great, it's like a friend explaining me without making me feel like a noob XD. Would like to see the advance narration system. Thanks and keep it up!!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you Pratik!
@LorenzoValente
@LorenzoValente Жыл бұрын
Gamedev here. The concept of decoupling is super important and this is clearly the right approach to deal with a one-to-many situation. BUT I would not recommend to create a Subject class that extends MonoBehaviour and force all your components that need to follow this pattern to be a subclass of Subject. Instead, just use C# events, which embed by definition the observer pattern, can be fully customized with the parameters you need and most importantly let you define them by composition and not by forcing you to inherit a specific class. And also they're super easy to use: "myEvent += myListener" to subscribe, "myEvent?.Invoke(parameter)" to fire the event!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
You're definitely not the only person to recommend this! And I agree!! But my reasoning for this tutorial is that I think that by creating our own observer pattern implementation, we gain a deeper understanding of the underlying concepts of event-driven programming and the observer pattern. And we can start to see how C# events and UnityEvents came about in the first place. That will make it easier to understand and work with Unity's event system. That's personally how I like to learn, at least. The use of UnityEvents is intended to come in the "advanced" tutorial :)
@Andrew-tl9gk
@Andrew-tl9gk Жыл бұрын
Did you guys ever heard about ReactiveX? It makes observables easy to use and comes with all operators you can think of. At least for JavaScript it is genius and makes life easy and the code clean and bug proof. I saw there is an implementation for Unity aswell called UniRx.
@Maverickkk
@Maverickkk Жыл бұрын
Another great video Nicky, keep doing what you're doing - you're proving to be an invaluable resource to the Unity community.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thanks so much Shaun!! :)
@MaximumSpice
@MaximumSpice Жыл бұрын
Learnt so much from this man, your editing and script work is insane. You will most certainly be a huge game dev channel soon bro
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you so much Maximum Spice! The channel just hit 50K!!
@MaximumSpice
@MaximumSpice Жыл бұрын
@@iHeartGameDev I saw bro, your on your way to over a million easily bro with content this well made!
@amdretm
@amdretm Жыл бұрын
YES PLEASE I would love to see an advanced version of this! I had so many ideas while watching this, like making it more generic to use different enums, avoiding inheriting Subject for more versatility, maybe making the events static... so many cool possibilities.
@Andrew-tl9gk
@Andrew-tl9gk Жыл бұрын
I think using ReactiveX there is no need to integrate of this yourself
@cypherparadigm3428
@cypherparadigm3428 Жыл бұрын
Very well put together video. It was concise and very informative. I myself am learning to be a developer and this video not only helped me with the observer pattern but gave me a better idea of what enums are. Which i have in a noise library but have never coded myself. So thanks a bunch. Liked and subscribed.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Hey! I love to hear that! Best of luck on your programming journey 😄
@cypherparadigm3428
@cypherparadigm3428 Жыл бұрын
Thanks. My biggest issue is still understanding the logic behind the codes. But with videos like these they get clearer and clearer. Edit: What I mean is video tutorials are nice to follow along and practice writing code, but it's these shorter videos that focus more on understanding that really help. So thank you again.
@evanknowles7543
@evanknowles7543 Жыл бұрын
I have no idea why KZbingorithm pushed this at me, but this was a great Observer pattern explanation.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Blessed by the algorithm 🤘 thanks for watching!
@petteriblomqvist8309
@petteriblomqvist8309 Жыл бұрын
Command + Observer implementation(s) definitely sounds like something I'd like to see more about, seems like something one would want to know how to apply efficiently. As if the rest of it really, but mostly that; I can see myself wanting to apply such for, well, probably 90% of whatever projects I might come up with. Generally anything that goes past the surface when it comes to the more common design patterns would be great, for those "Oo, I know what I could use that for " moments :D
@iKeaght
@iKeaght Жыл бұрын
Bro your content is awesome ! Keep it up I’m glad to be subscribed
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you 🙏
@dahstroyer
@dahstroyer Жыл бұрын
I really like these design pattern type videos
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you Dahstroyer! I like them too
@diegoreis3474
@diegoreis3474 Жыл бұрын
Nice video, but keep in mind that you should check if the list and the observers has null values when inserting, removing or notifying objects. This prevents the Subject class to notify or remove an object that already has been destroyed on scene. Even if you unsubscribe a observer from the Subject events in OnDestroy method, there is no way to know if the Subject already has been destroyed. Use null check to prevent this also.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Very good point!! :D
@sergiogcb97
@sergiogcb97 Жыл бұрын
Amazing video! Hope to see the advanced narration in the system, that would be super helpful for me! Keep the good work :)
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you very much Sergio!
@Ironlionm4n
@Ironlionm4n Жыл бұрын
Fantastic channel and looking forward to binging on your content
@GordonArber
@GordonArber Жыл бұрын
fantastic. can't wait to see the comman pattern
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thanks Gordon! I have a command pattern video already actually!
@marcusgray3525
@marcusgray3525 Жыл бұрын
Great explanation of the observer pattern, along with creating an example. Would love to see an advanced narrator tutorial video!
@abdou2247
@abdou2247 Жыл бұрын
Programming for production sounds pretty interesting! Looking forward to more content.
@james_coleman
@james_coleman Жыл бұрын
Great lesson. I'd love to see that advanced narration system tutorial!
@MafiaSniper
@MafiaSniper Жыл бұрын
Awesome! Easy to understand. Would love the advanced tutorial. Thanks!
@vladyjokey5790
@vladyjokey5790 Жыл бұрын
Great video, I would also like to see the advanced narration pattern in the future.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you Vlady!
@levildd
@levildd Жыл бұрын
This was great even as a beginner it was understandable and easy to follow! So glad I saw this thanks for posting this awesome video! Can't wait to see more!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
I LOVE to hear that. I try hard to make my videos as approachable as possible, so it means a lot that it’s beginner friendly. Thank you for sharing!
@ewwitsantonio
@ewwitsantonio Жыл бұрын
AWESOME! Def interested in the advanced version you mentioned :)
@xrqton
@xrqton Жыл бұрын
Waw outstanding work, thank you so much - best design pattern course at the moment :)
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Wow, thank you!
@nadav13IOY
@nadav13IOY Жыл бұрын
Wow this video is amazing, so detailed and easy to understand. I learnt a lot from it, thank you :)
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you Nadav!
@samuelhugo3387
@samuelhugo3387 Жыл бұрын
your hae to be the best, litterly no one else makes these kinds of ideos talking about these ery important things
@iHeartGameDev
@iHeartGameDev Жыл бұрын
That means a lot Samuel! Thank you 🙏
@darkmaigo
@darkmaigo Жыл бұрын
I'm interested to see more advanced projects in near future .... Awesome video and really helpful .. *Subscribed*
@ahmadel-baher8429
@ahmadel-baher8429 Жыл бұрын
Great video as always! The implementation you showed is elegantly simple and I think can make for a great base to improve upon. For starters: generics can potentially be used to define OnNotify with different types of arguments (though working with generics can sometimes be tricky!) Normally I use C# events with EventArgs to pass custom data, however this video inspired me to find a way to generalize my approach even further - Imma give that a shot when I have a chance!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Happy to hear that you had the idea of generics! Funny enough, the project files include a version of the pattern with generics that I was experimenting with :)
@buddhadebgreat
@buddhadebgreat Жыл бұрын
Amazing informative video can't wait to see the advance narration system. 🤩🤩
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Noted! It seems like a lot of people do. Thanks for watching :)
@reaperdev9857
@reaperdev9857 Жыл бұрын
I 100% want to see the Advance Narration System as I just so happen to be working on a passion project in Unity that would benefit from understanding how all this works better.
@HarshaKarteek
@HarshaKarteek Жыл бұрын
bro the explanation is top tier really amazing 👏👏👏👏👏
@diligencehumility6971
@diligencehumility6971 Жыл бұрын
Good video, well explained, if I were a beginner, I certainly would learn a lot. My two cent: This observer pattern is a very "Java thing", but implemented in C#. Nothing is wrong, but since we are in .NET, I would probably start with a public static Action OnDamageTaken { get; set; } in the Player script. This way, you communicate outwards from your player "hey, I took damage", and then all the systems that needs to react to it, can subscribe to this event. And build a system based on this. C# has "Action" and "Func" build-in for situations like this. But again, nothing is more right or wrong, do the system the best fits you. And for beginners; this is a legitimate pattern used in many languages.
@piobug
@piobug Жыл бұрын
Thanks!
@Chris-sd6sb
@Chris-sd6sb Жыл бұрын
For anyone who may have heard of the PubSub (publisher subscriber) pattern, the Observer pattern is the name used in the book, Design Patterns, by The Gang of Four. Great book. Definitely recommend it for newer programmers.
@adventuretuna
@adventuretuna Жыл бұрын
This is a really great introduction to the observer pattern. I think it's important to point out that observers should only be used in non-critical context. In this example, it is possible to stall the player's jumping logic if one of the observers does some intensive work, which may cause stuttering during gameplay. This might be frustrating to debug when it happens. Personally, I only use the observer pattern if the task that needs to be done can be discarded and not that critical to the gameplay (i.e. it's ok if the task does not happen or can be retried later). I've seen code bases that used this pattern to handle entire game states and that was not fun to debug.
@weeb_trassh52
@weeb_trassh52 Жыл бұрын
this was a brilliant vide, really easy to understand
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you so much!
@BonaMors
@BonaMors Жыл бұрын
it's a really useful content. Great explanation with working examples, so you can figure out why and how you can use a pattern for game architecture. Thanks
@iHeartGameDev
@iHeartGameDev Жыл бұрын
You’re most welcome! I’m glad you liked it!
@AngelCnderDreamer
@AngelCnderDreamer Жыл бұрын
Omu, I never thought programming is way complicated, I know it was but dang this just has a whole new level of coding! I am so happy I saw this, this actually showed up the right on time just what I need because I plan to rewrite my player code for my game to make it nicer and relearn the ropes of coding. I'll have to keep this in mind when i start writing the new code. Also I'd love to see more stuff like this, an advance and more in dept with audio narrators would be cool to see. :3
@spartianaleck
@spartianaleck Жыл бұрын
I too would be interested on seeing an advanced example narration system with command pattern being used in the future as well! Greate educational video by the way! It clearly made me subscribe to your channel as well :D
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thanks so much Aleck!
@hurshwardhannashine6128
@hurshwardhannashine6128 Жыл бұрын
dude ill try and implement this in my multiplayer game thanks, id love to see the more advanced one
@toni9305
@toni9305 Жыл бұрын
The way I like to implement the observer pattern is by using delegates and events, which are already part of C#, you create an event public property backed by a delegate and add listeners through the public property, this is waaay better than writting an interface and a Subject class for different needs, since Action already has template versions
@BarcelonaMove
@BarcelonaMove Жыл бұрын
This is a great tutorial mate
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Cheers, Loladín! :) Thank you!
@nein9420
@nein9420 Жыл бұрын
These videos are god-tier.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you 🙏
@argomix
@argomix Жыл бұрын
The explaination was superb! A very interesting take on the observer pattern. Right when I saw you were using interfaces on the trailer, I knew this was gonna be a different approach from what I know. I personally use C# events housed inside scriptable objects. Nice to learn some alternatives though.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Awesome. I’m happy to hear that you learned something new!
@silaszinn
@silaszinn Жыл бұрын
Hey man, lovelly video. You are in a great way and a love you channel. As a developer, It's good to see people like you doing this kind of video. But one thing to be careful with what you are teaching. Normally in unity people uses alot UnityEvents, Delegates and etc. So teach about Observer Pattern in that way without show this options can direct new developers to a complicated direction. Probably another video talking about that should be good. it's just a feedback to you increase your channel :) Keep rocking
@iHeartGameDev
@iHeartGameDev Жыл бұрын
You're definitely not the only person to recommend this! And I agree!! But my reasoning for this tutorial is that I think that by creating our own observer pattern implementation, we gain a deeper understanding of the underlying concepts of event-driven programming and the observer pattern. And we can start to see how C# events and UnityEvents came about in the first place. That will make it easier to understand and work with Unity's event system. That's personally how I like to learn, at least. The use of UnityEvents is intended to come in the "advanced" tutorial :)
@chris.davidoff
@chris.davidoff Жыл бұрын
The only thing I wish you added to this was showing the `event` keyword. It's the observer pattern in one line, basically :) It's not serializable, but Unity does provide the UnityEvent type which is, if you really want to use the inspector. but otherwise, this is a very killer and informative video, thank you!!
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Awesome -- I'm pretty confident UnityEvents will be what are used in the "advanced tutorial" but I think learning about the Observer Pattern _first_ allows developers to understand the built-in implementations from a base level. Now when we learn about UnityEvents, (I think) things might make more sense than they would have otherwise.
@chris.davidoff
@chris.davidoff Жыл бұрын
@@iHeartGameDev This is very true! You're right, it's best to show how to diy first :)
@senacheshmehkaboodi6867
@senacheshmehkaboodi6867 Жыл бұрын
Great video! Would love to see the more advanced version as well.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Awesome :) it will definitely happen!
@silenceplease6069
@silenceplease6069 Жыл бұрын
Great video, gave me good insights.
@codeFriendlyART
@codeFriendlyART Жыл бұрын
This is really cool stuff man and as usual, you nail it yet again by taking really complex subjects and break them down in such a way that makes them seems like if they are 'easy'. I just love the consistent style and formatting of your videos as well. Always learning from you man, keep up the great work and thanks a LOT!!! 👊😁 And I definitely would like to see how you do explain and introduce the Scriptable Objects and the Command Pattern implementations your style! I bet it would be awesome as well! - in a personal note I do find a little bit difficult to understand how to use Scriptable Objects - I've seen a few videos around from others, but to be fully honest with you, none of them has already explain their usage in a way that makes click to me.
@aethelierproductions
@aethelierproductions Жыл бұрын
Great tutorial! Who is your dentist and what is your skin routine?
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Lol thank you!
@alec_almartson
@alec_almartson Жыл бұрын
Great video. I would also like to see more about other programming patterns such as the Command Pattern (which allows you to implement features such as: Do & Undo Actions in your Games), Factory and Finite State Machine (I've heard that this is the most widely used in Video games, and also the Unity's Animator functionality itself is based on this one behind the Scenes).
@iHeartGameDev
@iHeartGameDev Жыл бұрын
I have tutorials on both the Command Pattern and State Pattern :)
@alec_almartson
@alec_almartson Жыл бұрын
@@iHeartGameDev Great! I will check them out 👍🏻 Thank You for creating such a Good Quality Content.
@sergibonell5400
@sergibonell5400 Жыл бұрын
I love these videos about design patterns, I think they're super useful for game development. I've used the command pattern a couple times but I would love to see your take on it (super useful for making undoable actions!). I have a question though, does creating your own Observer/Subject scripts provide any advantage over just using UnityEvents? It seems both can accomplish similar things.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
I think that implementing the observer pattern yourself can help you to understand the pattern better and help you to become more proficient in coding. But Unity Events are great and serve basically the same purpose
@sergibonell5400
@sergibonell5400 Жыл бұрын
@@iHeartGameDev Yes, I definitely agree! Thank you for your reply
@tugan_aa
@tugan_aa Жыл бұрын
Hello IHeartGameDev, I loved this video, you have explained all the details really nicely but I also want to mention that we call this Dependency on software programming and sometimes Notifiers or EventListeners don't really work for our project efficiently, which leads us to create an independent class or classes just to manage all actions and store data publicly or privately. You can always reach out about software stuff.
@UnityProgrammerAaron
@UnityProgrammerAaron Жыл бұрын
Love all your videos continue continue continue I am working on an MMORPG and seeing videos brushing my skills up thank you, and I am using that model in the video as my player as well :D lol
@NEEDCheese
@NEEDCheese Жыл бұрын
I love this channel. Thank you for the great videos.
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you for watching!
@Hector-bj3ls
@Hector-bj3ls Жыл бұрын
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.
@xirion11
@xirion11 Жыл бұрын
Awesome video 👍
@iHeartGameDev
@iHeartGameDev Жыл бұрын
Thank you!
@SHA3DOW_
@SHA3DOW_ Жыл бұрын
yess! advance narration system plzz.
How to Program in Unity: Command Pattern Explained
22:37
iHeartGameDev
Рет қаралды 70 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
How to Program in Unity: State Machines Explained
18:56
iHeartGameDev
Рет қаралды 235 М.
10 Things You NEED to Be Doing in Unity
11:40
Tarodev
Рет қаралды 137 М.
EASY Stats and Modifiers in Unity | Broker Chain Pattern
16:05
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 766 М.
Visitor: How I Mastered the Toughest Programming Pattern
12:59
The Most Common Mistake Beginners Make in Unreal Engine | UE5
12:17
Ali Elzoheiry
Рет қаралды 131 М.
every step to actually make your dream game (then sell it)
24:27
Unity async / await: Coroutine's Hot Sister [C# & Unity]
16:18
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН