How to Program in Unity: Observer Pattern Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 มิ.ย. 2024
  • 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:
    💛 / project-files-to-77632739
    ❤️ th-cam.com/users/iHeartGameDev...
    WANT MORE?
    Interested in learning more about animating characters in Unity? Check out my growing series of tutorials:
    ✅ • Unity's Animation System
    ✦ Like the vid? Please consider Subscribing!
    bit.ly/2YdIb6j
    ✦ Missed out on the last episode?
    • How to Move Characters...
    SOCIAL:
    ✦ Discord
    / discord
    ✦ Twitter
    / iheartgamedev
    ►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

ความคิดเห็น • 383

  • @iHeartGameDev
    @iHeartGameDev  ปีที่แล้ว +71

    ✨ 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 ปีที่แล้ว +1

      @@artistaartificial5635 Killer idea :P

    • @ZeroSleap
      @ZeroSleap ปีที่แล้ว +3

      ​@@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.

  • @pitchblack5422
    @pitchblack5422 ปีที่แล้ว +159

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

  • @mody1710
    @mody1710 ปีที่แล้ว +58

    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 ปีที่แล้ว +1

      show code Examples

    • @EvgeniPetrov
      @EvgeniPetrov ปีที่แล้ว

      UnityEvent is even more powerful as it gives ability to hook them up inside the editor

    • @johnandbuddy
      @johnandbuddy 11 หลายเดือนก่อน +1

      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 11 หลายเดือนก่อน

      @@johnandbuddy Not sure if this comment is targeted at me. UnityEvent has enough info on the net.

    • @johnandbuddy
      @johnandbuddy 11 หลายเดือนก่อน +1

      @@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.

  • @chris.davidoff
    @chris.davidoff ปีที่แล้ว +43

    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  ปีที่แล้ว +2

      Thanks for watching Chris! Good to know that sharing the preview is a good idea at the start!

  • @ZeroSleap
    @ZeroSleap ปีที่แล้ว +25

    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 ปีที่แล้ว +3

      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.

  • @KousseilaMd
    @KousseilaMd 3 หลายเดือนก่อน +2

    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 great ngl

    • @iHeartGameDev
      @iHeartGameDev  3 หลายเดือนก่อน +1

      Thanks so much!!!

  • @gabagpereira
    @gabagpereira ปีที่แล้ว +6

    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.

  • @PauloHSousa237
    @PauloHSousa237 ปีที่แล้ว +4

    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

  • @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

  • @omritahar-yakimgames4212
    @omritahar-yakimgames4212 ปีที่แล้ว +8

    Your videos are works of art Nicky. Their quality is simply unparalleled.

  • @emilsitell5484
    @emilsitell5484 ปีที่แล้ว

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

  • @Kitsune001Kei
    @Kitsune001Kei ปีที่แล้ว +15

    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  ปีที่แล้ว +2

      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!

  • @khicontocvang
    @khicontocvang 10 หลายเดือนก่อน

    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

  • @CollinPatrick
    @CollinPatrick ปีที่แล้ว +1

    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!

  • @VladaPersonal
    @VladaPersonal ปีที่แล้ว +1

    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.

  • @danielruizleyva3825
    @danielruizleyva3825 ปีที่แล้ว +2

    Ill love to see the next part of this project. Excelente job!

  • @Russellgamingstudios
    @Russellgamingstudios ปีที่แล้ว +3

    I’m currently making a Christian horror game thanks for all of your videos they helped me out

  • @ZebulonsPi
    @ZebulonsPi ปีที่แล้ว +7

    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!!

  • @PukiPuki
    @PukiPuki ปีที่แล้ว

    This was hands down the best tutorial/educational video I've seen in programming overall. I appreciate you so much, looking forward for more videos! Here's my sub!

  • @codeFriendlyART
    @codeFriendlyART ปีที่แล้ว +1

    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.

  • @ludodev
    @ludodev ปีที่แล้ว +3

    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!

  • @GrahamOfLegend
    @GrahamOfLegend ปีที่แล้ว +5

    Excellent tutorial as always! Keep em coming please, you're def one of the best on TH-cam 🙏🏽

    • @iHeartGameDev
      @iHeartGameDev  ปีที่แล้ว +1

      Graham! Thanks so much for the kind words, bro!

  • @Ironlionm4n
    @Ironlionm4n ปีที่แล้ว +1

    Fantastic channel and looking forward to binging on your content

  • @NightStudios
    @NightStudios ปีที่แล้ว +5

    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  ปีที่แล้ว +2

      Thank you for such kind words! It truly means a lot!

  • @Twelveoglock1
    @Twelveoglock1 ปีที่แล้ว +1

    This was amazing! Great video, would love to see you keep going.

  • @chuckchuk14
    @chuckchuk14 ปีที่แล้ว +4

    Fantastic video, as always! You're the new GOAT for good game dev practices. Love your videos.

  • @ShinStalk
    @ShinStalk ปีที่แล้ว +1

    Would gladly watch the continuation of this character’s adventure in the observers world

  • @darkmaigo
    @darkmaigo 10 หลายเดือนก่อน

    I'm interested to see more advanced projects in near future .... Awesome video and really helpful .. *Subscribed*

  • @MafiaSniper
    @MafiaSniper ปีที่แล้ว

    Awesome! Easy to understand.
    Would love the advanced tutorial.
    Thanks!

  • @silenceplease6069
    @silenceplease6069 ปีที่แล้ว +1

    Great video, gave me good insights.

  • @SolFuture
    @SolFuture ปีที่แล้ว +4

    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  ปีที่แล้ว +2

      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!

  • @leosalazar9213
    @leosalazar9213 ปีที่แล้ว +1

    I have seen other vídeos about the topic but i feel this is the first and only time i could understand it xp

  • @faridbehrouzi6228
    @faridbehrouzi6228 6 หลายเดือนก่อน +1

    Best video about the observer pattern I found so far. Thanks a lot.

    • @iHeartGameDev
      @iHeartGameDev  5 หลายเดือนก่อน

      Wow, thanks! That's quite the compliment!!

  • @LorenzoValente
    @LorenzoValente ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      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.

  • @gamemacher87
    @gamemacher87 ปีที่แล้ว +8

    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 8 หลายเดือนก่อน

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

  • @felfurion8624
    @felfurion8624 ปีที่แล้ว +1

    Great. Yes to the advanced tutorial on this topic would be welcome and I'll look forward to the procedural animation video.

  • @maybetall
    @maybetall ปีที่แล้ว

    Thank you. Yesterday I built a system that should have used the observer pattern. Time to decouple.
    This also gives me an idea on how to handle audio, which I'm trying to work on right now. I was trying to avoid coupling.

  • @wicgamesdev
    @wicgamesdev ปีที่แล้ว

    Thank you for the Knowledge!

  • @TheKr0ckeR
    @TheKr0ckeR ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      Thank you so much! This was a fun one to make!

  • @travellerinthedark
    @travellerinthedark ปีที่แล้ว +2

    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.

  • @puntalic
    @puntalic ปีที่แล้ว

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

  • @HarshaKarteek
    @HarshaKarteek ปีที่แล้ว

    bro the explanation is top tier really amazing 👏👏👏👏👏

  • @iKeaght
    @iKeaght ปีที่แล้ว +1

    Bro your content is awesome ! Keep it up I’m glad to be subscribed

  • @postman428
    @postman428 ปีที่แล้ว +1

    I never knew i need this tutorial,
    So helpful, Thanks!

  • @rehrocks
    @rehrocks ปีที่แล้ว +1

    Ive Just pause the video to say, you are awesome, the way you show and solve the problem is perfect, thank you

  • @ewwitsantonio
    @ewwitsantonio ปีที่แล้ว +2

    AWESOME! Def interested in the advanced version you mentioned :)

  • @raigautista
    @raigautista ปีที่แล้ว

    That's a really great great explanation :D

  • @abdou2247
    @abdou2247 ปีที่แล้ว +1

    Programming for production sounds pretty interesting! Looking forward to more content.

  • @hpzero4207
    @hpzero4207 ปีที่แล้ว +3

    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

  • @AbdullahGameDev
    @AbdullahGameDev ปีที่แล้ว +1

    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👏.

  • @ThanhNguyen-po7zy
    @ThanhNguyen-po7zy ปีที่แล้ว +1

    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!

  • @sergiohere12
    @sergiohere12 ปีที่แล้ว +1

    Amazing video! Hope to see the advanced narration in the system, that would be super helpful for me! Keep the good work :)

  • @Jesh31G
    @Jesh31G ปีที่แล้ว +2

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

    • @iHeartGameDev
      @iHeartGameDev  ปีที่แล้ว +1

      Thanks so much Jesh! :) I tried to make it as beginner friendly as possible

  • @AngelCnderDreamer
    @AngelCnderDreamer ปีที่แล้ว +1

    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

  • @evanknowles7543
    @evanknowles7543 ปีที่แล้ว +1

    I have no idea why TH-camgorithm pushed this at me, but this was a great Observer pattern explanation.

    • @iHeartGameDev
      @iHeartGameDev  ปีที่แล้ว

      Blessed by the algorithm 🤘 thanks for watching!

  • @weeb_trassh52
    @weeb_trassh52 7 หลายเดือนก่อน +1

    this was a brilliant vide, really easy to understand

    • @iHeartGameDev
      @iHeartGameDev  7 หลายเดือนก่อน

      Thank you so much!

  • @MaximumSpice
    @MaximumSpice ปีที่แล้ว +2

    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  ปีที่แล้ว +1

      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!

  • @levildd
    @levildd ปีที่แล้ว +1

    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!

  • @Departageance
    @Departageance ปีที่แล้ว +2

    That's really interesting. Thanks for this video. Multiple subjects would be a topic I'd like to see in your next video.

  • @t90gamemakervietnam8
    @t90gamemakervietnam8 10 หลายเดือนก่อน

    It's so really cool. Big thanks to you

  • @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

  • @james7491
    @james7491 ปีที่แล้ว +2

    event Actions are also a great implementation of the observer pattern, I use them a lot for decoupling

  • @james_coleman
    @james_coleman 5 หลายเดือนก่อน

    Great lesson. I'd love to see that advanced narration system tutorial!

  • @jacksoundwave2091
    @jacksoundwave2091 11 หลายเดือนก่อน

    This channels deserves way more subscribers

  • @Chopi
    @Chopi ปีที่แล้ว +1

    Great video!!!

  • @buddhadebgreat
    @buddhadebgreat ปีที่แล้ว +1

    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 :)

  • @BarcelonaMove
    @BarcelonaMove ปีที่แล้ว +1

    This is a great tutorial mate

    • @iHeartGameDev
      @iHeartGameDev  ปีที่แล้ว

      Cheers, Loladín! :) Thank you!

  • @GordonArber
    @GordonArber ปีที่แล้ว +1

    fantastic. can't wait to see the comman pattern

    • @iHeartGameDev
      @iHeartGameDev  ปีที่แล้ว +1

      Thanks Gordon! I have a command pattern video already actually!

  • @pratikdeshmukh7508
    @pratikdeshmukh7508 ปีที่แล้ว +2

    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!!

  • @nadav13IOY
    @nadav13IOY ปีที่แล้ว +1

    Wow this video is amazing, so detailed and easy to understand. I learnt a lot from it, thank you :)

  • @BonaMors
    @BonaMors ปีที่แล้ว +1

    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!

  • @paulembleton1733
    @paulembleton1733 ปีที่แล้ว +1

    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.

  • @xrqton
    @xrqton ปีที่แล้ว +1

    Waw outstanding work, thank you so much - best design pattern course at the moment :)

  • @petteriblomqvist8309
    @petteriblomqvist8309 ปีที่แล้ว +2

    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

  • @ahmadel-baher8429
    @ahmadel-baher8429 ปีที่แล้ว +2

    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  ปีที่แล้ว +1

      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 :)

  • @marcusgray3525
    @marcusgray3525 ปีที่แล้ว

    Great explanation of the observer pattern, along with creating an example. Would love to see an advanced narrator tutorial video!

  • @diegoreis3474
    @diegoreis3474 ปีที่แล้ว +10

    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.

  • @hex9219
    @hex9219 ปีที่แล้ว +1

    awesome job

  • @cypherparadigm3428
    @cypherparadigm3428 ปีที่แล้ว +1

    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.

  • @diligencehumility6971
    @diligencehumility6971 ปีที่แล้ว +2

    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.

  • @varan9412
    @varan9412 ปีที่แล้ว +1

    Really cool video👌

  • @EMPERENIKA
    @EMPERENIKA ปีที่แล้ว

    super use full!!!

  • @Maverickkk
    @Maverickkk ปีที่แล้ว +1

    Another great video Nicky, keep doing what you're doing - you're proving to be an invaluable resource to the Unity community.

  • @XadegamerOfficial
    @XadegamerOfficial ปีที่แล้ว +1

    Sure will like to see it

  • @dahstroyer
    @dahstroyer ปีที่แล้ว +1

    I really like these design pattern type videos

    • @iHeartGameDev
      @iHeartGameDev  ปีที่แล้ว

      Thank you Dahstroyer! I like them too

  • @xirion11
    @xirion11 ปีที่แล้ว +1

    Awesome video 👍

  • @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

  • @SHA3DOW_
    @SHA3DOW_ ปีที่แล้ว +1

    yess! advance narration system plzz.

  • @hurshwardhannashine6128
    @hurshwardhannashine6128 ปีที่แล้ว +1

    dude ill try and implement this in my multiplayer game thanks, id love to see the more advanced one

  • @NEEDCheese
    @NEEDCheese ปีที่แล้ว +1

    I love this channel. Thank you for the great videos.

  • @spartianaleck
    @spartianaleck ปีที่แล้ว +1

    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

  • @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.

  • @andrewreddin8853
    @andrewreddin8853 ปีที่แล้ว +1

    Great Video!!!

  • @VaderNgoDev
    @VaderNgoDev 6 หลายเดือนก่อน +1

    You saved my day!!!!

    • @iHeartGameDev
      @iHeartGameDev  5 หลายเดือนก่อน

      That's amazing! Glad to help!

  • @vladyjokey5790
    @vladyjokey5790 ปีที่แล้ว +2

    Great video, I would also like to see the advanced narration pattern in the future.

  • @senacheshmehkaboodi6867
    @senacheshmehkaboodi6867 ปีที่แล้ว +1

    Great video!
    Would love to see the more advanced version as well.

    • @iHeartGameDev
      @iHeartGameDev  ปีที่แล้ว +1

      Awesome :) it will definitely happen!

  • @ryster52153
    @ryster52153 ปีที่แล้ว

    Thanks!

  • @faus585
    @faus585 ปีที่แล้ว +1

    this is cool!!

  • @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.