How To Build An Event System in Unity

Sdílet
Vložit
  • čas přidán 28. 08. 2024

Komentáře • 515

  • @MortMort
    @MortMort Před 4 lety +61

    This channel needs more love

  • @ElegantWaster
    @ElegantWaster Před 5 lety +181

    This is really great and very concise. You have quickly become my favourite Game Dev channel on here.

    • @GameDevGuide
      @GameDevGuide  Před 5 lety +22

      Wow, thank you! That really means a lot.
      I'm trying hard to strike a good balance between informative and entertaining. I'm presenting a lot of things I think go undeserved by a lot of other channels, and honestly my content for these videos are mostly from things I'm using day to day during development - stuff I wish I'd learned\heard about when I was first getting started. So I'm really glad you're finding it useful! Thanks for the kind words! 😊

  • @Seb_Ibrahim
    @Seb_Ibrahim Před 4 lety +85

    Your content is amazing. I'm so tired of the same beginner how-to stuff that ends up being a pile of spaghetti code and can't really be used in medium to large projects. This was much needed. Thank you and keep the videos coming! ❤️🙏🏼

    • @vintoncerf7562
      @vintoncerf7562 Před 2 lety +4

      This system is not performant since he is id checking for every single door in the scene.
      Let's say we have 1000 doors in the scene. The id checking code will run 1000 times whenever a single door is opened. In other words, we say the following to the computer:
      You: "Hey dude can you open this door for me please?"
      PC: Wait pal, first I need to know which door is that what's the id?
      You: The id of the door is 0.
      PC: Ok just wait while I'm comparing that value to all thousand doors.

    • @2n974
      @2n974 Před rokem

      @@vintoncerf7562 that's not true at all

    • @vintoncerf7562
      @vintoncerf7562 Před rokem

      @@2n974 why?

    • @MaikoYT
      @MaikoYT Před rokem +1

      @@vintoncerf7562
      If you want to make sure the right object handles an event, you can assign the event to a delegate in a Dictionary. Then, when the event is triggered, you can specify which object to call the function on using its instance ID. This way, you can make sure that the function is only called on the specific object you want.

  • @Chocochoco22
    @Chocochoco22 Před 4 měsíci +1

    I've been watching so many Event tutorials and for some reason after this tutorial, everything that I watched started making sense now

  • @AetherXIV
    @AetherXIV Před 3 lety +5

    I like how you explain the concept first. It actually helps to teach us how to code, not just show us what you did.

  • @Sevendogtags
    @Sevendogtags Před 5 lety +184

    How do you not have like a 100k subs already? Your videos are so nice and high quality!
    Thanks!

    • @Jay12321Jay
      @Jay12321Jay Před 4 lety

      Just thought the same... Strange!

    • @MassimoRough
      @MassimoRough Před 4 lety +1

      Have you already shared this video so he would get closer to 100k?

    • @zakkaioken2812
      @zakkaioken2812 Před 4 lety +1

      That's because they don't upload often enough uwu

    • @MassimoRough
      @MassimoRough Před 4 lety

      Zak Kaioken 2 how do you measure that?

    • @zakkaioken2812
      @zakkaioken2812 Před 4 lety

      @@MassimoRough measure it by quality / content / count / topic / focus
      if you're not making good content on topics people care about fast enough, enough times, you will not grow that fast.
      people call it the CZcams algorithm, but, the fact is, if people care they will share.

  • @roderickmorgan2115
    @roderickmorgan2115 Před 4 lety +12

    I've got to echo all the comments below, this is one of the quickest, clearest and most aesthetically pleasing dev tutorials I've seen on youtube.

  • @tsvetansumerski7231
    @tsvetansumerski7231 Před 2 lety +2

    I've been watching videos on events for days and this is the only video that actually explained it well enough for me to understand, thank you!

  • @kartiktiwari2008
    @kartiktiwari2008 Před 4 lety +14

    The event system was doing my head in. But you solved it in 8 minutes amazing stuff!

  • @alexbukk556
    @alexbukk556 Před 4 lety +12

    This is the BEST Unity event tutorial I've seen so far! I've been looking around for some practical, example based tutorials for understanding both the general use case and implementation details for event systems. It's a shame I had to watch so many other tutorials before I found this one, that in 5 min covered more than the previous five tutorials I've watched combined. Keep up your good work, and THANKS for this awesome video :)

  • @simoxeh
    @simoxeh Před 2 lety

    I've been trying forever to understand events. I finally think I understand it. May you have many blessed days and may your descents know nothing but happiness

  • @ironsfamily6
    @ironsfamily6 Před 4 lety +4

    This was amazing. I think I need to come back when I'm not so sleep deprived, do a little background research, and try this out for myself to get the full benefit, but I didn't know about this functionality and never thought about programming this way. This is incredible. Thanks!

  • @michaelsissons234
    @michaelsissons234 Před 4 lety +6

    Utterly fantastic, most tutorials available on youtube have serious pacing and clarity issues, and yet you made it look effortless.

  • @KarasawaL30
    @KarasawaL30 Před 4 lety +5

    Been learning C# on my own for a year now and so far, your videos have been the best for concise, step by step explanations. A lot of guides don't take the beginner mindset into account, and simply push forward into glossing over and including a lot of extra concepts that end up making things harder to understand. Cheers!

    • @DannyBoy443
      @DannyBoy443 Před rokem

      I don't like that either. I'm beginning to think that this channel (and others, if I'm being honest) don't think its a good idea to do the basics because it isn't sexy or too low level and boring. Which if that's the case, I disagree with wholly lol

  • @rickloyd8208
    @rickloyd8208 Před 4 lety +2

    After a week, I came back here to say THANK YOU! This pattern is awesome, I just used it in an upcoming project, everything looks easy to understand, clean and safe!

  • @Antman261
    @Antman261 Před rokem

    THANK YOU! I come from a web dev background and build a lot of event-driven and/or event-sourced distributed systems. I've just started building a game as a hobby. SO, naturally, I decided to punish myself early and went looking for an event-based implementations in Unity. The first few forum posts and packages I came across made me doubt the entire approach, but this is precisely the kind of clean, simple, straightforward thing I LOVE! Thank you!

  • @stephenbacunot4334
    @stephenbacunot4334 Před rokem

    You are a living god among n, a legend worthy of praise. What you've uploaded here, will echo into eternity!

  • @MrBsehratmaannking
    @MrBsehratmaannking Před 4 lety +1

    im a CS master student who was always quite interested in game dev but in my bachelor and master we havent learned so much about game dev and looking at unity, i always felt somewhat overwhelmed with all the custom functions in unity. Just found your channel today and it gives me a nice starting point to at least see all the options in unity

  • @lesthodson2802
    @lesthodson2802 Před 3 lety +50

    "An object known of as the subject"
    *distant linguistical screeching*

  • @ast_rsk
    @ast_rsk Před 4 lety +8

    The quality of this channel is unreal. Keep it up! If you're looking for suggestions on topics, it would be great to get some insight on project planning, scoping, and starting small for new developers (those most likely to find your videos useful).

  • @xuanhungdo7285
    @xuanhungdo7285 Před 5 lety +8

    Welp, this was one of the most helpful videos for GameDev in unity. Clean, fast and simple tutorial. Great job!

    • @goodusername4901
      @goodusername4901 Před 3 lety

      he goes faster than a minecraft dream speedrun but it's very helpful!

  • @kristianthaler6525
    @kristianthaler6525 Před 2 lety

    I was here months ago and didn't get it at all, now it's super clear to me. Progress.

  • @joaquinfraustoalfarorocco8177

    let me tell you, this just leveled up my overall coding pipeline, simple, concise a work of art this tutorial

  • @512Squared
    @512Squared Před 2 lety +2

    One of the clearest Dev tutors on CZcams!
    I love how you anticipate questions and problems, as well as giving a bit of top-level background to the code/unity concepts you are invoking. Top job fella!

  • @mahimagupta8283
    @mahimagupta8283 Před rokem

    It's truly astounding how easy the internet makes learning these days. Thanks for the tutorial, my guy.

  • @Caldaron
    @Caldaron Před 4 lety +48

    Fun fact. Having a prefab setup (door with trigger zone) for this is way easier and doesnt require to call multiple methods to figure out if this is the right door. people are going to use events from now on when it doesnt even make sense.

    • @snaileri
      @snaileri Před 2 lety +7

      Yea, bad example in the video. Well explained, but people shouldn't use an eventsystem for generic doors.

    • @Pietrofonix
      @Pietrofonix Před rokem +2

      A fair example of how events should be used?

    • @cheapgrams2955
      @cheapgrams2955 Před rokem +1

      Why not?

    • @n1ppe
      @n1ppe Před rokem +4

      ​​​@@PietrofonixFor example if there's a level in your game and there's some button or a lever that causes something to happen in some other part of the level (like unlock something or open some door or whatever), you could have an event and listen to it, and then do it when it happens.
      You could also use events for example when the player collects something and you want to have some kind of an effect on the UI.
      Basically if you want something to happen somewhere else when something happens.
      In the example of the video though, you could just have a script on the door that opens it when the player enters the trigger collider, making the event system unnecessary.
      Sorry for my English :)

  • @JordanLiver
    @JordanLiver Před 3 lety +1

    I’ve watched this several times and finally pushed myself to use it during a game jam. It worked so well for what I needed! Thanks for the concise explanation and example! It really helped me grow as a programmer.

  • @marcus_vdm
    @marcus_vdm Před 2 lety

    It took me a little while to wrap my head around this concept, but as my project grew bigger I really needed something like this! Now that I finally understand it I use it all the time! Thank you for explaining it properly and clearly!!!

  • @hamzazahid4705
    @hamzazahid4705 Před rokem

    IT WORKED, THANKS I'VE BEEN LOOKING FOR THIS FOREVER, BUT NO TUTORIAL COULD EXPLAIN IT AS YOU DID

  • @user-dm5qi4nb6l
    @user-dm5qi4nb6l Před 3 lety

    I'm having trouble digesting all this about patterns, and now you just made a key subject easy to understand, I really appreciate that.

  • @TuberTugger
    @TuberTugger Před 4 lety +1

    This stuff is gold! I've watched a handful of your videos now and I'm astounded by how useful they are.
    Please keep up the good work.

  • @nemlinkacompany7577
    @nemlinkacompany7577 Před 4 lety +1

    I love your content.
    Fast + clean + VERY usefull.... I never saw channel like this (most are too unprepared)
    I really wish you success

  • @JDoerp
    @JDoerp Před 4 lety

    I’ve been trying to achieve exactly what this video has explained for four days and not been able to until now. Earned a subscriber. First time I’ve come across your channel. Thank you!

  • @Fenixmaiden666
    @Fenixmaiden666 Před 4 lety +1

    A clear and concise video explaining events. I was self-taught with code, so I had been coding for a while before I started to understand events and how to utilise them. Even after learning about them, I still didn't really use them as I had to step out of my comfort zone. Really good explanation and usage to introduce someone to events though. Kudos!

  • @psinjo
    @psinjo Před 4 lety +1

    I want to thank you for the simple tutorial, it was pretty short, to the point, and showed off the syntax + a decent implementation (along with parameters) keep up the good work!

  • @owencoopersfx
    @owencoopersfx Před rokem

    This is an excellent tutorial. I would like to point out though that in this example you actually can eliminate the Singleton by instead making GameEvents a static class and making all its methods also static. The only times you need a Singleton are when you need to create/destroy/track runtime data/objects. If all you’re doing is managing events, you don’t need the Singleton. Hope this helps people.

  • @charmaebritania9406
    @charmaebritania9406 Před 2 lety

    It really worked for me after I look and try some tutorials, yours is the one that worked. Owe you a lot.

  • @TheMenkin
    @TheMenkin Před 2 lety

    This has become one of my favorite design philosophies for quick prototyping, and even in some production builds over two years. I've used this for two major game jams, and it has amazingly reduced coding time drastically , although it can be a hard concept to grasp for other devs on short time span. I cannot recommend this tutorial enough. If you have trepidations about it, try it out, it might change your world as much as it did mine.

  • @tricky_fat_cat
    @tricky_fat_cat Před 4 lety

    I used to use a C# events before I learned about Unity events, but your video gives a new look on them. Thank you.

  • @mauco4037
    @mauco4037 Před 3 lety

    Maybe I am a bit late to thank you, but your video saved me hours of suffering... Thanks a lot! Keep up your good work!

  • @richystocles
    @richystocles Před 2 lety +4

    "swimming in a big bowl of spaghetti code"... you are watching me right !?

  • @VladimirDemidovIllusiveMan

    I wish i would have seen this video one month ago when I started my project, now I have a spaghetti of dependencies that i have struggled to maintain in order, but with this I could have had such a great system.

    • @VladimirDemidovIllusiveMan
      @VladimirDemidovIllusiveMan Před rokem

      So, i was using Localization package in unity and it didnt go well with webgl, i decided to make my own translation. I have a binary file with texts, and one static dictionary. all texts in the game should take info from that dictionary. I had no idea how to do this, but this video gave me the perfect one. I connected to every TMPro text (they are the observers? correct me if im wrong) a script with a function that changes the text. When a button to change language is pressed, the dictionary is updated with data from a file, and then an event is generated, every label gets updated with a new text. If i did anything wrong then please tell me, im open to learning new things :)
      Thank you GDG for an amazing video. Got a sub right then and there :D

  • @lando6583
    @lando6583 Před 4 lety +1

    love the video format! I appreciate you speeding up the coding sections and highlighting actual gameplay functionality.

  • @heatherelroy9534
    @heatherelroy9534 Před 2 lety

    This was great. To the point. Quick typing. No extra fluff. Loooove it.

  • @twomanstudio3249
    @twomanstudio3249 Před rokem

    I'm working on a project right now and this video really saved me! Thank you so much!

  • @karim009
    @karim009 Před 5 lety +9

    Hi, cool video, but I recommend putting the subscribe/unsubscribe lines of code in the Enable/Disable methods, because unless you call DestroyImmediate you don't really know when the object is destroyed.

  • @ardwennem
    @ardwennem Před 2 lety

    Thanks for this video, I have seen a lot of event systems that didn't implement it with parameters, this was the first one that did! This really makes things a lot easier :)

  • @mehmedcavas3069
    @mehmedcavas3069 Před 4 lety

    I was looking for months like a tutorial like this. everyone shows an example which makes no sense or don't give even a good example. thanks

  • @Bloodthirst
    @Bloodthirst Před 4 lety

    One other way that i manage events is to encapsulate them in a GameEvent scriptableObjects , then i create a GameEventListener script where i create a GameEvent field i can plug my event SO , and a UnityAction field for the listeners , i find that waay more flexible and more editor friendly. Good content man , this is helping many people get their code cleaner ! :)

    • @GameDevGuide
      @GameDevGuide  Před 4 lety +1

      Yeah, this is another great way to handle it, especially if you're working in the editor often or want designers to be able to set up relationships easily.
      I personally find it a bit messy, as it can be a lot harder to debug and understand the relationships at a glance. But there's never one right way to do something! Just whatever is best or easiest for the project at hand!
      Glad you enjoyed the video!

  • @sufianahmad7337
    @sufianahmad7337 Před 3 lety

    After 7 or 8 videos I finally got a focused video 😊 Thank you

  • @ali51717
    @ali51717 Před 3 lety

    as a programmer, I am just looking for design and planning, because I am confident I can write the code.
    This is why I find it perfect

  • @rakowumusic5143
    @rakowumusic5143 Před 2 lety

    That is so damn well explained. Short and sweet but without leaving out a single thing. You answered all my questions in record time. Thank you for the great video.

  • @tomjesten3945
    @tomjesten3945 Před 4 lety +5

    Just found this channel. There is a lot to learn from you. :)

  • @blunygeorge
    @blunygeorge Před 3 lety

    When I first saw this video I tried this out but didn't understand why it may be a good idea. Today while I was casually implementing my smol game, I came across this problem: I would have had to add a chain of events. "A" happened in class X -> "A" happened in class Y that contains multiple X instances -> "A" happened at YManager class, which manages multiple Y instances. The last two would have been new events. This is just in order for a UI element to know about a specific event that happens in class X. Instead of adding these two new events, for now I went with something similar that the video shows. This way it is a "global event", and there isn't any additional event that only exists to pass further up the event. There isn't an unnecessary chain.
    Thanks for the idea.

  • @kyleme9697
    @kyleme9697 Před 3 lety

    This is the first Events video I've seen that said anything about unsubscribing from the Events ... seems kinda important :)

  • @ChaosCain4
    @ChaosCain4 Před 4 lety

    This really made the way event systems work a lot more clear for me. Thanks a lot, hope you have a good day!

  • @jackpeterson1909
    @jackpeterson1909 Před 4 lety +2

    This is high quality content! You cover topic that's actually important. Thank you

  • @nickolas6060
    @nickolas6060 Před 2 lety

    Finally someone that explains this clearly! Many thankd👍👍

  • @akaHarvesteR
    @akaHarvesteR Před 4 lety +1

    When I need subscribers to return data to the event source, what I usually do is set up a query class that I then pass as a parameter on the event. Then responding subscribers can add in their replies as needed to that query. That way you have full control over how to manage potentially multiple responses to your event's ´question´.

  • @agentrsdg
    @agentrsdg Před 4 lety

    Really need more content like this which focuses on code and architecture

  • @noelabella3287
    @noelabella3287 Před 4 lety +1

    Heaps of thanks, I figure it out! Please make more of these! This helps me in my assignment.

  • @simoncodrington
    @simoncodrington Před 4 lety +1

    What a great video mate. Love how you've animated it to keep it interesting. Cheers

  • @vainiusgames2709
    @vainiusgames2709 Před 4 lety

    your video improved my life

  • @Etocles64
    @Etocles64 Před 3 lety

    Wow, what a clear, concise, and informative video. Absolutely amazing work, thank you!!!

  • @ARandomSub
    @ARandomSub Před 4 lety +3

    Uhh this just changed everything for me! Thanks!

  • @minecraftermad
    @minecraftermad Před 4 lety

    if brackeys and such are 10/10 this is 11/5 tbh.. these have helped me so much more with critical things than those channels have :)

  • @ivanmoreno25
    @ivanmoreno25 Před 4 lety

    Thanks a lot! I was having an issue with Unity crashing when some events happened, so I watched this video to check what was wrong with my code. Your example worked perfectly.
    Later I realized that the problem was an infinite recursion lol

  • @RegoneFF
    @RegoneFF Před 4 lety

    Your video is great and all but I'm not sure this is the best example of an event system.
    TL;DR
    Don't be afraid of errors in log, they are here to help you and you will only learn from it for the next time.
    Longer version
    I once worked with a guy who had a similar approach to programming where he rather not notice a bug and make everything run "smoothly" with no apparent stuff breaking around than seeing a bug popping 50 times in the log/ crash the game and then fix it or just did the system too dynamic where it shouldn't, like doors or other "static" stuff that doesn't really change through the run.
    he had such a hard time finding and fixing a single bug.

  • @64imma
    @64imma Před 3 měsíci

    I made a simple game in unity recently, and i definitely am guilty of just passing in a whole bunch of dependencies into the inspector and having to bounce information through several scripts and game objects just to get a simple thing to happen. I want to keep making games, but i now see how important it is to plan the code out so that new features are effortless to implement and existing ones to maintain.

  • @mementomori7160
    @mementomori7160 Před 3 lety

    I just witnessed your channel go from 66.5k to 66.6k subscribers. That's a nice number, but should be multiplied by 10(at least)

  • @hhhhhhhhhhhhhhhhh159
    @hhhhhhhhhhhhhhhhh159 Před 2 lety

    that was the funniest unity tutorial video i have ever seen :D

  • @MikeArcuri
    @MikeArcuri Před 3 lety

    This was great! My computer science education is 25 years old, and I'm pretty new to C#, but I was able to follow this lesson the first time, get it all working, and understand the basics.
    It wasn't clear to me why we needed both the public methods and the public events defined in the GameEvents object, but a few edits to try to call the events directly from the TriggerArea objects showed me via C# errors that this isn't allowed.

  • @Bashar3A
    @Bashar3A Před 4 lety

    Something I've been trying to confused how to do for long time. Thank you! Subscribed

  • @rCr101990
    @rCr101990 Před 4 lety

    This is great, sounds like combining Mediator pattern with Observer using Events and Singleton. Nice

  • @TheMapaSoft
    @TheMapaSoft Před 4 lety +49

    Well, I stumble on your video and I must say that is a very naive implementation of an EventSystem.One of the problem I see is the event payload. Each time you add arg to the event, you must change the code everywhere to accommodate the right Action signature. The other one is the tight coupling inside your GameEvents class. As the project goes, the amount of events will increase and your GameEvent class will be packed with all the types for every aspect of your game, UI, gameplay, music , sounds, etc... The last one, is your "none" implementation of a SingletonBehaviour class... Having a lone static method in your gamevent class does not shield you from having multiple instance running, each one overriding your static Instance.

    • @faythe03
      @faythe03 Před 4 lety +8

      What could make the event system better? Why? I'd like to learn

    • @psyneur9182
      @psyneur9182 Před 4 lety

      I agree with you that there is a very tight coupling between the game's events and this class, it does mean this class could become very long (especially considering it will essentially be a list of types and duplicate methods). However, having to change the code when the type of the Action is changed is not a problem, imo. If you don't have to change the code, where is the type safety?

    • @Zethneralith
      @Zethneralith Před 4 lety +7

      ​@@faythe03 A good example is the Windows Forms event system that uses an EventHandler generic delegate (found in the System namespace). The real magic is in the TEventArgs which, by default, has no properties. This is meant to be expanded upon by inheritance.
      For example, to create an event that sends information about a collision, you could create a class that looks like this:
      class CollisionEventArgs : EventArgs
      {
      public HitInfo Collision { get; set; }
      }
      The signature for the event would look like this:
      public event EventHandler OnCollision;
      And can be raised as expected: (assuming hitInfo is defined)
      CollisionEventArgs args = new CollisionEventArgs();
      args.Collision = hitInfo;
      OnCollision.Invoke(this, args); // Passing "this" for sender as a reference to the object raising the event.
      Effectively you use the same method shown in the video, but use EventHandlers, instead of Actions. They're both delegates, but EventHandler gives you some extra consistency via the generic type parameter.

    • @Cebbinghaus
      @Cebbinghaus Před 4 lety +1

      This same System could be Implemented Much closer to Unities Event built in Event system using the `Component.BroadcastMessage` Method. Have something like a Trigger Enter call Broadcast Message and suddenly only the single gameobject that Gets Entered has its Event called opposed to Every Door in the entire game

    • @TheMapaSoft
      @TheMapaSoft Před 4 lety +13

      @@faythe03 Hi Valentin, sorry for the delay, Covid-19 stuff.... Well, for me, being a AAA game dev, I prefer a total separation between the sender of the event and the receiver. In C#, you have event, but you need to subscribe to the sender (most of the time). This could be avoided, by having a static class that contains only the C# events you need. It could work. But my preferred way is by using an EventChannel. A channel, which is a Singleton, is only responsible to let the event pass into it. You can listen for any Type of event, when the event comes in, you will be notified via callback. Also, for the event itself, I prefer using a class (struct could works also). It may hold any other types, so the payload is almost free. And on top of that, to minimize the memory fragmemtation, you can pool the events. To give you an example : GameplayChanne.Instance.StartListenFor(OnThisEventCallback).... I can paste code here if you want.

  • @Jagent
    @Jagent Před 4 lety

    Never before have I needed knowledge so badly without realizing it. Thank you for this!

  • @gabrielcoleman3267
    @gabrielcoleman3267 Před 4 lety +89

    Overall great tutorial. One thought, Instead of assigning a Unique ID to each script, an easier way would be to get the gameobject.InstanceID, which would save time of needing to make sure each door has a unique ID.

    • @NotASpyReally
      @NotASpyReally Před 4 lety +2

      yes that's what I thought

    • @qwerty81808
      @qwerty81808 Před 4 lety +21

      Why bother with any of that? Why not simply pass the GameObject or Component calling the event as a parameter?

    • @Gahanun
      @Gahanun Před 4 lety +3

      The id allows one trigger to open multiple doors and vice versa. + the way you suggest it doesn't work since both the trigger and the door need to have the same id.

    • @gabrielcoleman3267
      @gabrielcoleman3267 Před 4 lety +2

      @@Gahanun Well, good point. I made that suggestion without trying it out. However, a modification that I believe will work is if you have a parent GameObject with both the door and the trigger as children. The event system could use the transform.parent as a substitute to the ID, and simply trigger an event if the door's transform.parent is the same as the trigger's transform.parent. I can see however, that this might not be ideal for all scenarios, and simply using an ID might be the optimal solution, if the intention is to do away with directly referencing GameObjects in code.

    • @nachostv4217
      @nachostv4217 Před 4 lety +1

      @@qwerty81808 Without being an expert on the subject, I'd say passing the entire GameObject would be sending along far more data than is actually needed. I assume it will want to know about everything in the GameObject, so all variables and whatever, this will cause a lot of unneeded CPU instructions (reading from the RAM to get that information) when all you really need to send along is a 16-bit integer.

  • @alicepricesaeibi4282
    @alicepricesaeibi4282 Před rokem

    As for me, everything is simple and clear. Thank you very much

  • @dariussparkes7080
    @dariussparkes7080 Před 4 lety

    A brilliantly constructed guide.

  • @Ruzakisan
    @Ruzakisan Před 4 lety +1

    omg it is the most clean explanation of events and it using in Unity! God bless you +sub

  • @Oxmond
    @Oxmond Před 4 lety +1

    Great tutorial! Accurate and clear description and great code. Well done! 👍🤓

  • @Xiromtz
    @Xiromtz Před 4 lety +2

    Great video for a simple "event system"! I think it would be important to note the biggest difference between the observer pattern and an event system: An event system should be time decoupled, which your implementation is not. This means the eventsystem would have some sort of queue where events are queued, and at some later point in time the eventsystem would go through that queue and call event subscribers. A great showcase of this pattern is in the book "game programming patterns".

    • @immersiveirl6638
      @immersiveirl6638 Před 4 lety +1

      IMHO, the ideal scenario is that the events are handled immediately, but then the handler queues tasks.
      eg: void myEventHandler(int id) { StartCoroutine(DelayedHandeler(); }

    • @Xiromtz
      @Xiromtz Před 4 lety +1

      @@immersiveirl6638 Starting a coroutine doesn't really do anything here. It's a bit of a misconception that coroutines are "parallel", all they do is run in the main thread until a "yield" statement tells it to stop running for this frame or for however long the yield statement tells it to.
      The optimal solution in Unity would be a simple queue or stack, where a "fire_event" function would add the event to the queue and the class containing the queue would work through events in its update function.
      The idea is to decouple heavy event handling functions from the caller, but we must also assume events can't be handled immediately. So the use-cases would be something like an achievement or sound system, where a delay of one or two frames is not noticeable. This kind of system might not, for example, work with an input system.
      If an event is immediately handled, it is nothing more than an observer pattern, albeit cleaner with the use of delegates and such. Nothing bad about it, just nitpicking with terminologies.

    • @immersiveirl6638
      @immersiveirl6638 Před 4 lety

      @@Xiromtz I understand that a Coroutine is not true parallelism, but dumping the task into a Queue and processing in Update is effectively the same as doing it in the EventHandler... it's still all being done in one frame. Unless you're limiting the number of tasks that get popped from the queue per Update, at which point you should probably be using a Coroutine for style (processing over multiple Updates).

    • @Xiromtz
      @Xiromtz Před 4 lety

      @@immersiveirl6638 Oh yeah, you mean something like a coroutine that stays alive for the whole duration of execution? I did something similar once and you would be correct, that does sound like the cleaner solution. Using a time budget per frame and thend yielding until the next once the budget is expended sounds like a really good implementation.

  • @HeroSnowman
    @HeroSnowman Před 4 lety

    Your tutorials are so simple and understandable, keep doing this!

  • @GameBob
    @GameBob Před rokem

    As a new Dev I actually have had no problems with dependencies and I've been working day and night on my game for months. I think the major thing that trips people up isn't spaghetti code, it's not keeping track with concise verbage in the code.
    I have a code manager object that handles most "global events" that does the trick and keeps from getting to confusing. However I have a lot of simple dependant code that goes from object to object because it was the most straightforward answer to the problem at hand, or the best way to make it operate with efficiency. Being new I might not fully grasp it yet but from my current understanding it can be daunting to say that what new devs are doing is wrong when it might work better for them. It can really hurt someone's ambitions. Not saying it's a bad thing for this video to tackle, I've just noticed this trend and the first time I saw it I thought to myself "if I can't do it the way they say I should I'll screw it up and it'll all be for not" and if I wasn't as determined as I am I might have given up.

  • @manugamingcreations1021

    Thanks a lot! Managed to make a similar thing in Javascript thanks to this tutorial!

  • @Aceleo209
    @Aceleo209 Před 4 lety

    I spent 13 seconds in this video. Liked the video..subbed and made a comment

  • @varunshivaram711
    @varunshivaram711 Před 5 lety

    Keep making amazing videos like this to explain kinda complex stuff simple...as an aspiring game dev I loved the video...you deserve more subs, I'll make sure to like,sub, refer, and tweet...keep up the good work.

  • @flameprincess7313
    @flameprincess7313 Před 2 lety

    "Yes I am aware of the irony" sounded so cute honestly

  • @PauloSamurai
    @PauloSamurai Před 3 lety

    after many times, I finally got it! thanks man!

  • @LordEmpalvs
    @LordEmpalvs Před 3 lety

    Thanks for the video! I found this pattern extremely helpful for triggering changes in the UI. Its very boring and messy to make direct connections between logic components and UI components. Using events you can just fire away upon input and let the needed components listen to it and do what they need to do.

  • @llorex1
    @llorex1 Před 2 lety

    Great video as always!

  • @zakaruPL
    @zakaruPL Před 4 lety

    Great quality of video! keep your work doing mate 🤜🤛

  • @kapresovsk
    @kapresovsk Před 4 lety +1

    plethora ... wow a new word that i yet haven't heard before. i wonder if i will hear it again :)

  • @sreerone9562
    @sreerone9562 Před 5 lety

    Hey Man, thanks for Sharing the knowledge and supporting the community.. Cheers!

  • @kirtanvinodbhaivekariya413

    Thank you So much for ur ti and support

  • @lunforgettablel
    @lunforgettablel Před rokem

    This was so helpful!! Thank you

  • @fluffykaeloky675
    @fluffykaeloky675 Před 4 lety +1

    You can use the UnityEvent class to benefit from automatic Unity serialization, as well as null protection if your GameObject was destroyed.

  • @jaancaro3829
    @jaancaro3829 Před 4 lety +1

    I love you

  • @joshowens8628
    @joshowens8628 Před 4 lety +1

    This is a great tutorial - though I typically use UnityEvents over C# events because of the easy integration with the editor