Events & Delegates in Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ม.ค. 2025

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

  • @anussqadeer3181
    @anussqadeer3181 ปีที่แล้ว +107

    This 13 minute long video has more than 3 years of experience in it

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

    Never has someone explained the different event types more clearly to me. Impressive.

  • @TheOnlyArtifex
    @TheOnlyArtifex ปีที่แล้ว +53

    Absolutely the best way I've ever seen delegates and events been described (even without the context of Unity). Events and delegates are quite abstract and difficult to grasp for beginner programmers, but the order and detail with which you described them here was perfect. I'm going to remember this video if anyone every asks about them!

  • @cheesymcnuggets
    @cheesymcnuggets ปีที่แล้ว +14

    I feel like I have just ascended to a high plain of existence after gaining this knowledge, absolutely criminal that this video only has 14K views after nearly a year. I will definitely be rewatching this video a few times a week until it sinks in. I barely know how to program and it's probably too soon for me to start using something like this, I have no projects that really need this but I want to know more, events are so cool, I'll try and find an excuse to use it. This explanation was so in-depth that I completely forgot this is not what I was trying to research out of pure interest and wonder. I hope one day I will the one explaining this to someone new

  • @LucasBlizzard
    @LucasBlizzard 9 หลายเดือนก่อน +6

    This video is amazing. No waffling, no interruptions, straight to the point, and rich in information.

  • @justafancybluebird
    @justafancybluebird ปีที่แล้ว +14

    This video is actually insane holy, there is absolutely 0 waffling and no over complication to sound sophisticated and extra. Insane video, great job.

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

    This video is super high quality!
    Was surprised it didn't have more views then just realized it was published yesterday even though the blog article was published last year 😂.
    Your content is head and shoulders above all other entry-level content out there for Game Devs. Please keep it up!

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

      Thanks so much!

    • @humadi2001
      @humadi2001 2 ปีที่แล้ว

      Same

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

      Exactly, it started from beginning, shows theory and than practical applications. Then explains benefits. This was 5th video about events/delegates I saw and only one I understood. Hehe

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

    Who allowed the video to be THIS GREAT ???

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

    I've been working on a pause menu for quite a while and these delegates were very helpful. (Thank you for the video)

  • @VRWarehouse
    @VRWarehouse 2 หลายเดือนก่อน +1

    Finally an explanation I can understand, good job.

  • @MagicCubeWorld
    @MagicCubeWorld 2 หลายเดือนก่อน +1

    Thank you so much, this is brilliant. Going to need to watch this a few more times to really absorb it all. Subbed.

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

    This tutorial is extremely well done and super high quality. I wish all tutorials were made like this. Amazing work.

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

    These videos are great. Glad you expanded to TH-cam!

  • @aarndal90
    @aarndal90 10 หลายเดือนก่อน +1

    This is a beautiful done video. Thank you so much. 🙏 You've definitely earned my subscription a thousand times.

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

    This topic has previously frustrated me and this video explained it clearly, thank you.

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

    This video saved my game from massive Performance issues. Thank you for making this so easy to understand.

  • @Radidar
    @Radidar 2 หลายเดือนก่อน

    This was a good video.
    As someone who has been using Unity as a game designer since 2016 and is self-taugh in coding, this video helped me understand the underlying system under the Action type that I've been using for years :D

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

    Awesome lesson. I found it really useful to be able to use both Unity and Action events from 1 scriptable object. Thank you!

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

    it is wacky how underrated you are

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

    fantastic tutorial man, really cleared this up. I've been aware of events and delegates for a while but wasn't ready to understand them yet, this makes a lot of sense. Thanks man!

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

    Idk how many times i have watched this by now, amazing

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

    are you kidding me? This is such a great tutorial my guy! The observer pattern goddamn!

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

    This is a really really *really* good video for anyone looking to improve the use of patterns in their game.. Very well presented and clear

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

    I wish this tutorial was there two years ago. It would've saved me enormous time of learning. Thank you!

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

    i am about to finish due to how amazing this video is

  • @mpbMKE
    @mpbMKE 8 หลายเดือนก่อน

    I wasn't even looking for this, but it was exactly what I needed. The observer pattern is super easy to understand at a high level, but I always get stuck in the implementation weeds. And SO Events! What a great idea! I'll definitely be coming back to this for reference until it all sinks in.

    • @GameDevBeginner
      @GameDevBeginner  8 หลายเดือนก่อน +1

      Happy to help! I can't take credit for SO events, I learned about them from Ryan Hipple, he did a great talk about them here: th-cam.com/video/raQ3iHhE_Kk/w-d-xo.html

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

    Awesome video, clear explanations, thank a lot and wishing that you keep posting more about game architecture in Unity!

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

    Awesome video, very well explained and useful.
    I like how you don't straight up explain a very specific thing such as Scriptable Objects, but start from its simplest form (delegates) and THEN explain the more interesting stuff.

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

    This video is so unique!! Many videos tell about Action. Many others discuss on Delegate. But only your combined them all.

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

    this is really professional, I always avoided using events I had to watch it two times, but I think this 10 minutes video covers a lot of information. I like it it's straight forward and goes into why use one over the over. Thank you! I will watch this one more to make it clear. Really high quality and doesn't waste a second. This is not for beginners but a beginner can understand it if he spend some more time with it than watch it once.

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

    One of the best tutorials I've ever seen. I was always confused about why events were used over delegates. Saved me a ton of time.

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

    Nice video!
    I needed a reminder about the syntax and differences between all the keywords and you covered everything!

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

    Game dev beginner?? More Game dev expert! 😉
    Great and neat tutorials sir. I will come back for more in the future.

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

    3 seconds into the video and you already earned a sub

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

    I have gone through many videos none of which triggered the ah hah moment like this one.
    Nicely described, great speed, these must take a while to make, instant subscription!

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

    That was more comprehensive and sophisticated than my algebra in highschool ! I really enjoyed and admire you for such a precise explaining video . keep it up dudes

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

    This is amazing! Structured, well-explained with no useless info
    Love it!

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

    This came at just the right time! I was needing a video explaining this just earlier today. Thank you.

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

    I don't really comment on anything, but this was super helpful. Thanks. The best description I've come across on how to use delegates and also the types/alternatives (static, events, and actions).

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

    this is teaching. sensing when and how strongly your audience is not understanding something on a particular point. great work!

  • @Crons-v3f
    @Crons-v3f 2 ปีที่แล้ว

    Man, this was the tutorial that I needed a year ago, I made so many uneccessary calls and conditions when I could have used this, my code is complete spaguetti.
    You just made me want to refactor using this event and delegates, thanks man !!

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

      Glad it helped!

    • @Crons-v3f
      @Crons-v3f 2 ปีที่แล้ว

      @@GameDevBeginner It certainely did, I will watch all the other videos as well, you gained a new subscriber. Thanks again!

  • @reshha9885
    @reshha9885 2 ปีที่แล้ว

    dude these are really polished videos i hope many devs discover this channel

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

    Thanks buddy, it was really helpful!

  • @flamertor
    @flamertor 2 ปีที่แล้ว

    Really good explanation and high quality video. Well done! Helped a lot more than the Unity Docs

  • @twinguy9633
    @twinguy9633 10 หลายเดือนก่อน +3

    I think this wasnt explained in a simple way at all but I suppose for intermediate people it would be good enough

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

    Thanks for your work!

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

    best video and way of teaching, thanks a lot :)

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

    Thanks a lot, explained so well!

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

    This is super useful, thanks!

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

    Great video! Thanks for explaining so clearly and detailed. I think the video chapters are missing: 7:42 Unity Events

  • @HiHi-iu8gf
    @HiHi-iu8gf 2 ปีที่แล้ว

    wait this video is actually so good

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

    6:02 i like how when he says "subscribe" youtube thinks he's telling us, viewers, to subscribe, and lights up the subscribe button

  • @Maskeowl
    @Maskeowl 6 หลายเดือนก่อน

    i never kknevv about delegates vvork flovv before thnx a lot

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

    Great video!

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

    Thank you for sharing this video, it is very useful for me.

  • @mehmeh8883
    @mehmeh8883 2 ปีที่แล้ว

    Everything I needed!
    Also would be cool if were to cover other design patterns :D

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

      Thanks! You can expect one on singletons for sure

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

    3:01 - I am a bit confused... If you have to first make a template for the delegate, then create an instance, that would mean that you can make multiple instances of the same delegate type. Why would that be useful? Maybe when having, for example, multiple enemy types triggering the same delegate type, but wanting them to do different things. But that seems impractical to me, but idk, I'm a noob lol

  • @Krwatkins0002
    @Krwatkins0002 2 ปีที่แล้ว

    Very well explained, thank you so much.

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

    In my opinion, scriptable object event is the best, easy to make, test, debug and can use them in different project.

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

    I tried to implement the Scriptable Object Events, but allowed the Event Listener to hold a List of GameEvents. I did this, so that I don't have to add multiple Event Listener components to an object, that trigger the same method in the unity event. Unfortunatly, that led to "NullReferenceException: SerializedObject of SerializedProperty has been Disposed" errors, when assigning or deleting game events from the list in the inspector, that were printed every frame to the console, especially in Inspector mode (not during runtime or aswell). Does anyone know, why the serialization has issues with lists or arrays in this context?
    Thanks

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

    What is the colorful mini menu that tells you what type of code you're using in VS code? I like that

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

    Thanks for this

  • @radiocage
    @radiocage 2 ปีที่แล้ว

    This is great, you're great!

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

    What if you want initially inactive GameObjects in a scene to subscribe to events that cause them to become active? I can't figure out a good way to do this.

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

      It can be a little more tricky to do it this way but it's still possible, try using Awake and On Destroy instead.

  • @namtrinh9335
    @namtrinh9335 8 หลายเดือนก่อน

    this video is so good

  • @Ironlionm4n
    @Ironlionm4n 2 ปีที่แล้ว

    Incredible content

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

    Thanks! You help me a lot :)

  • @RodrigoP3ssoal
    @RodrigoP3ssoal 3 หลายเดือนก่อน

    Legend. I just have one specific question... I've setup the Scriptable Objects Game Events system on my game, but sometimes I want so that when an event is triggered, a value is returned from the subscribers, but I don't see with clarity how that could work? I've thought about using Funcs, because it can return a value, but how to I merge the concepts of Funcs and Scriptable Objects Game Events in a clean way?
    Thanks!

    • @GameDevBeginner
      @GameDevBeginner  3 หลายเดือนก่อน

      So the way you'd normally do this is use Func, or a delegate type that returns a value, but because scriptable object events use Unity Events to trigger responses, that's where your issue is. I don't know if there's a way to return data from a Unity Event. So, this could work, but you'd probably need to remove the Unity Event part of it, and have scripts subscribe directly to the Func in the scriptable object. This is just off the top of my head, it's not something I've tried.

  • @rbsalmon7895
    @rbsalmon7895 2 หลายเดือนก่อน

    Checked out various tutorials about this topic but my negative iq couldn't quite fully grasp the concept.
    Now after watching this video I can confidently say that I REALLY regret not knowing about this sooner. I'm 2-3 months in on a project and this could've made my life so much easier. I'm not sure if refactoring my previous progress is worth it so I guess i'll try implementing events going forward

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

    You should do Unity/c# courses, you have a really good didactic

  • @halivudestevez2
    @halivudestevez2 2 ปีที่แล้ว

    but exactly when should we declare global game events? what are the real world situations for this?

  • @halivudestevez2
    @halivudestevez2 2 ปีที่แล้ว

    To reply to the last question:
    I don't like to connect things in the inspector - it is very fragile for me, and makes the code unfollowable: creates a hidden feature which is cannot be seen in the code.

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

    Not beginner friendly imo, but an excellent video. The issues some may have might stem from using all sorts of technical terminology that those who are programmers or more actively learning game development can get but most beginners will absolutely lose you once you start talking about subscriptions, function containers, and basically making the transcript of this video look like HAM radio instructions 😢

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

      Thanks for the feedback 👍🏻

  • @louie2
    @louie2 3 หลายเดือนก่อน

    goddam youre a good teacher

  • @contraband.software
    @contraband.software ปีที่แล้ว

    Hey man, how do you do it so that your Unity and code is high resolution even when you zoom in on it in editing?
    Thanks :)

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

      I record the screen at 4K, that's all I do really!

    • @contraband.software
      @contraband.software ปีที่แล้ว

      @@GameDevBeginner damn it might be time to get a 4k monitor 😭

    • @contraband.software
      @contraband.software ปีที่แล้ว

      @@GameDevBeginner btw I hate to be a pain, but what do you think of my videos? I'm trying to make videos similar to yours so I was wondering if you have any criticisms

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

      I don't know if how I make videos is a good example to follow, I'm just trying my best really, but I do think that the most important thing is not to overcomplicate what you're showing, or to waste time on stuff that's not relevant, both of which you seem to already be doing so 👍🏻. Then it's just a case of iterating, just keep doing it and you'll work out where the value is, the best way to present things, what people respond to etc. If you have other questions, email me at support@gamedevbeginner.com and I'll try to help.

    • @contraband.software
      @contraband.software ปีที่แล้ว

      @@GameDevBeginner thanks so much that's very helpful:)

  • @KoolakStudio
    @KoolakStudio 2 ปีที่แล้ว

    very nice , dude

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

    I Like your tube, but I have a question about using static to event? the event should be static?

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

      the event doesn't have to be static, but if you're making a global event then making it static means that every script can access it without a reference to an instance of that class.

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

    What I learned:
    *Delegates* alone are volatile, and should be avoided when possible.
    *Static Events* trigger, then stuff happen from there.
    *Action events* are like Static Events, but you don't have to write the delegate first, and it does about the same?
    *Unity Events* are drag and drop in the inspector.
    *Scriptable Object Events* are two step triggers. They have a list of Unity Events, and then the events each have arms of functionality attached to them. They're kind of like an Event Event.

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

      👍🏻 delegates are still useful though, for example if you need to create an event function that takes a parameter AND returns a value, you'd need a delegate for that.

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

    You need a C# basics in Unity course or video series.

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

    is the event Action a type of singleton?

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

      Not exactly, but if you make it static it's globally accessible, so it kind of works in the same way

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

    I've noticed you name your game objects and assets (except scripts) with spaces in between words. This is exactly what I'm doing, and I had a huge argument with my boss who kept insisting that this is just asking for problems and shouldn't be done this way. Since he's the boss, we're doing what he says, but in my solo projects I still use spaces between words. Never had any hint of an issue with it. What would be your argument in favor of using this type of naming, other than readability which is the most obvious one?

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

      To be honest, this isn't something that I've ever thought about until now but it seems like it could be good practice to make sure that files and folders don't have spaces, for the sake of tools that need to read a file path. but as for objects in the scene, I'm not sure that it matters. But, this is the sort of thing that, if someone's telling me I must never, ever, do it, then they should be able to give a pretty clear reason why not.

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

    Coding shit is so fucking complicated as abstracts. Once I put it into practice, though, it becomes a hell of a lot easier to comprehend. Hope I get the hang of this when I need it 😅

  • @3bomb
    @3bomb 2 ปีที่แล้ว

    GOOD STUFF

  • @thatguitarguy99
    @thatguitarguy99 2 ปีที่แล้ว

    Also can’t you programmatically add listeners to a UnityEvent? The video makes it seem like you can only use the inspector to subscribe. I know UnityEvents are the least performant option but they do seem the most straightforward for a variety of cases

    • @GameDevBeginner
      @GameDevBeginner  2 ปีที่แล้ว

      I believe that you can, I just can't think of a reason why you would? Since, if you're doing it in code anyway, why not just use Actions or Event Delegates? I'd like to know some use cases for doing it that way though, is it that you'd want the flexibility to do both from one event type?

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

    Hmm, love everything in the video except for the scriptable objects solution. It gets a bit messy in my opinion, certainly if you have a lot of events. Furthermore, you have to reference everything in the inspector (Unity scenes don't go well with source control) I'd suggest using a static event bus instead

  • @watercat1248
    @watercat1248 2 ปีที่แล้ว

    i still do not understand what Delegates means i know what Events but what Delegates do ?

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

      A delegate is a reference to a method pretty much.
      Example:
      Let's say you have a method called "ButtonPressed" on a class called Button.
      A button has obvious functionality. You can press it! But what is the button supposed to do when pressed?
      Well that's already the wrong question! What the button does when it's pressed is not something the button(class) itself should worry about.
      Instead, it should delegate that task to another method.
      You can have many instances of the same class of Button, but each individual instance can have a different reference(delegate) to a method it is supposed to trigger.
      I recommend reading more into Actions, Functions and Events on the official C# Microsoft Documentation.
      This video talked mostly about unity specific events, which I'm somehow not a big fan of. Using the inspector isn't really viable if you have to spawn in a lot of your gameplay elements at runtime.

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

    Baba büyüksün 👌👌

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

    If you make tools, UnityEvents are godly

  • @nizzoh
    @nizzoh 2 ปีที่แล้ว

    Thank you

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

    thank u

  • @DerAua
    @DerAua 2 หลายเดือนก่อน

    Subbed.

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

    72 views only? I must share this

  • @cl2401
    @cl2401 3 หลายเดือนก่อน

    horizons expanded!

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

    i think the best way to explain this to someone would be , its basicly a button that presses a button xD

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

    Awosame !

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

    Beautiful way of explaining, but too theoretical & complicated to be applied

  • @inyourhead9714
    @inyourhead9714 2 ปีที่แล้ว

    I had to watch this upwards of 5 times, going back and forth between screens of code. I think some restating of relationships, writing important phrases on-screen, a few more diagrams and a spoken example would have allowed me to comprehend this on a single viewing. Because of this, I cannot recommend this video. Great voice actor though.

  • @zamika2100
    @zamika2100 3 หลายเดือนก่อน

    It's hands down the best explanation about delegates and events! I've been struggling to fully grasp this subject for a long time, but now I really understand it! I just should watch it a couple more times to make sure that I did.
    THANK YOU!