[C#] Delegates and Events (E02: events)

Поделиться
HTML-код
  • Опубликовано: 25 авг 2024

Комментарии • 205

  • @RaidenFreeman
    @RaidenFreeman 8 лет назад +232

    These 2 tutorials are EXCELLENT. Short, correct, to the point, and well informed. I know how to use delegates and events, but wanted to watch them anyway; you understand coding principles, and I'm really happy that you're explaining them to people, in the best way even! Just telling someone to "prefer" events, is useless, he does not understand where and when to use them; explaining which problems they solve is much more effective. Great job.

    • @SebastianLague
      @SebastianLague  8 лет назад +18

      Thank you!

    • @Repsack2
      @Repsack2 6 лет назад +5

      This exactly, i wanted to write something similar, but i am not at all surprised that other viewers agree. Very informative tutorials!

    • @randomCADstuff
      @randomCADstuff 2 года назад

      "Just telling someone to "prefer" events, is useless," ... I totally agree! I've been watching so many videos that just use events and don't explain what they're actually doing. Worse yet, they are using them when they don't need them by conjuring up redundant examples, like where one would never actually use an event in a real project.

  • @jollejollejolle
    @jollejollejolle 7 лет назад +71

    This is by far the best video I've seen on delegates events. I really love that real life example. Thank you for good content.

  • @rkpixeldesign
    @rkpixeldesign 8 месяцев назад +2

    i think this is the best video in the world to understand the concept of delegates, event, action and func. It seem so natural. Anyone who wants to learn about this concept in any programming language is welcomed here

  • @Lordofcookiejars
    @Lordofcookiejars 5 лет назад +12

    Just a note, Unity recommended practice is to handle event subscription in the OnEnable() method instead of Start() (and unsubscribe in OnDisable()). This is to ensure consistent behavior if you disable+re-enable or destroy the game object later.

  • @stanislawmenschow8894
    @stanislawmenschow8894 Год назад +2

    I can't believe I watched so many confusing videos before this and started to think I'm dumb ... and then 14 minutes from 6 years ago immediately made everything crystal clear. Thank you.

  • @xyxean
    @xyxean 5 лет назад +19

    0:17 that went dark real quick i love it

  • @glebpalchin6809
    @glebpalchin6809 7 лет назад +6

    I am watching a lot of Unity tutorials for about 8 months, free and paid tuts, but yours are the best, because you cover information not just about basics, which is the most problem of other youtubers. Great job!

  • @3333218
    @3333218 4 года назад +1

    Many other videos on the subject over-complicate things without explaining how, when and why to use Delegates, Events, Actions and Funcs.
    You were able to explain all of these things clearly in less than 20 minutes.
    Well done, and thank you!

  • @kruth6663
    @kruth6663 3 года назад

    One of the best tutorials I found about delegates and events. Short, clear, straight to the point, and with awesome bonus tips about Action and Func. Thanks!

  • @Fouriersoft
    @Fouriersoft 4 года назад +1

    Best tutorial on delegates around. Cheers Sebastian :)

  • @ericvosselmans5657
    @ericvosselmans5657 2 года назад

    You are a very gifted individual Sebastian Lague

  • @muzboz
    @muzboz 5 лет назад +6

    "Create the func!"
    Still trying to get my head around a good working example of when this is really useful to do, versus other techniques.
    But this definitely helped! :D

  • @weepigaming
    @weepigaming 2 года назад

    I have seen a lot of tutorials (by a lot I mean by the hundreds) and this is one of the best tutorials I have ever seen. ty!

  • @atauygur8852
    @atauygur8852 5 месяцев назад

    You are a legend, I am getting amazed every time I watch one of your videos.

  • @Hassane_B
    @Hassane_B 4 года назад

    You proved that most of other tutorials makers about events in c# do not understand what they are trying to explain to, I thought the events topic was complex but now thanks to you Sebastian I know their explaining methods are complex

  • @andreibazi
    @andreibazi 4 года назад

    I want to further stress the point of how excellent, clear and straight to the point this tutorial is. I've watched 2 more before this and still had questions that were really quickly answered by yours. Thank you very much for the awesome content Sebastian!

  • @sandeep10au
    @sandeep10au 5 лет назад

    For years I struggled to understand what is delegates and events, why to use them and when to use them... But these two videos have helped me finally understand what exactly they do and when to use... Thanks a ton for such amazing videos!!!

  • @lusonatuga5741
    @lusonatuga5741 2 года назад

    I have found it difficult to understand and implement these concepts but luckily I was able to understand much better with these videos. Thank you!

  • @theyellowarchitect4504
    @theyellowarchitect4504 6 лет назад

    I come here once a month to refresh the details between delegates/actions/funcs, and I have to say, thank you so much :)

  • @THEspindoctor84
    @THEspindoctor84 2 года назад

    this is incredibly helpful. I've been looking at some online resources about actions, events, delegates and such. This is the only one I've seen that really clarifies the fact that the "event" keyword is NOT A TYPE. It is a keyword applied to a delegate. Thank you!

  • @daichi_devs
    @daichi_devs 4 года назад +1

    As a noob game dev, this really helped me understand these intimidating concepts. Thank you so much Sebastian.

  • @luislodosm
    @luislodosm 5 лет назад +35

    2:32 now you can do deathEvent?.Invoke(); instead of checking null with if.

    • @garbage_person
      @garbage_person 3 года назад +2

      Sorry this is two years later but, is this a functionality only for delegates or could one use it in a different capacity?
      Consider:
      Target target = GetComponent();
      target?.enabled = false;
      //instead of below
      Target target = GetComponent();
      if (target != null)
      target.enabled = false;
      Any idea where I could read up on this? Tried Googling for a while but couldn't figure out how to phrase the search.
      Thanks.

    • @imSoCalamari
      @imSoCalamari 3 года назад +3

      @@garbage_person Yes, that is valid. This is called the "null-conditional operator", which you can read about in the Microsoft C# Programming Guide documents. Here is a link to the specific section: docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and-

    • @garbage_person
      @garbage_person 3 года назад +1

      @@imSoCalamari awesome. Thanks so much for the info.

    • @THEspindoctor84
      @THEspindoctor84 2 года назад

      @@garbage_person yah it basically helps you check if the object is not null before calling a method from it, or getting an attribute from it.

    • @holmbergen
      @holmbergen 2 года назад

      This is called Null-conditional operators (?.) if anyone wants to look it up, it's available in C# 6 and later.

  • @filmamundo9194
    @filmamundo9194 2 года назад

    thank you so much, i watched lots of tutorials about events and delegates, and you are the only one who actually showed them in a simple and pratical way

  • @lee1davis1
    @lee1davis1 6 лет назад +1

    Thanks much! I watched several videos and documentation, but never fully understood how to use delegates and Events until this vid. Thanks again.

  • @AlexeyFilippenkoPlummet
    @AlexeyFilippenkoPlummet 4 года назад

    Can't say enough how this tutorial is so much better than all the other c# event tutorials I've seen on YT.

  • @mowztouch4873
    @mowztouch4873 6 лет назад +5

    Sebastian Lague, i learn so much in your vids... Thank you!

  • @bit_casper
    @bit_casper 4 года назад +1

    This made me understand delegates better than any resource i've studied. This deserves more views!

  • @simonhooper9071
    @simonhooper9071 7 лет назад

    Love it, expressing how and 'why' we should write code the right way. The way that saves us trouble. Lovely demonstration of SRP - This is the best example i have seen in why and how to use events. I'm book marking this to show my minions at work! Great job!

  • @amuletgames1046
    @amuletgames1046 4 года назад

    This is the best explanation I have heard so far about Events, I used them by following other people tutorial but without knowing how to the explain its usage to myself, right now i just 3 mins in and it already made alot more sense.

  • @jafran8783
    @jafran8783 Год назад

    The most excellent coverage on this topic. Thank you!!!

  • @Wallabee01
    @Wallabee01 4 года назад

    I was struggling for 2 days to figure out delegates and events, these two videos finally made it all click!

  • @jeffherlache8569
    @jeffherlache8569 8 лет назад +14

    I've struggled with these concepts quite a bit. These videos helped to make things clearer to me since they have the explanation followed by good examples of how to use them.
    Thank you so much for making these tutorials!

  • @notveryobservant1056
    @notveryobservant1056 2 года назад

    I like this little series, I feel that I wouldn’t really be able to learn this kind of thing directly most of the time (in other tutorials) so it’s nice to have these things addressed.

  • @sadoqdraws1170
    @sadoqdraws1170 4 года назад

    you are awesome bro, thank God that people like you exist on earth!

  • @excalibur4856
    @excalibur4856 3 года назад

    Man, this dude's tutorials are S tier, best I've found in a long time

  • @andrewhiser9965
    @andrewhiser9965 2 года назад

    Fantastic tutorial. I'm learning Unity and hadn't been able to understand events until watching this video. Thank you so much, you earned yourself a sub.

  • @gilbasaurus
    @gilbasaurus 4 года назад

    Thank you, Sebastian. These tutorials were the most helpful and least confusing ways to learn delegates and events I've found over the past few days. Keep up the good work

  • @yannickfrogel3537
    @yannickfrogel3537 2 года назад

    Best tutorials i have ever seen about coding

  • @theGreaterAwareness
    @theGreaterAwareness 7 лет назад +6

    I'll have to re-watch this about 10 times before it clicks but I have a feeling this video is going to make it click. I'll try do some small scenes to practice. Thankyou for these videos.

  • @joeloyolabordagaray5265
    @joeloyolabordagaray5265 3 года назад

    WOW! It became clearer in 6 minutes than in one and a half hour of lecture at my university.
    Thanks!

  • @JohnnyThousand605
    @JohnnyThousand605 2 года назад

    Six years on and this is a timeless classic =)

  • @rungeon83
    @rungeon83 4 года назад

    Honestly I've been struggling to understand delegates for years so didn't use them, but your tutorial helped me completely grasp it! thank you! I'm now using Godot which relys heavily on "signals" aka delegates, while also using c# I can use signals still, but C# delegates seem way more powerful. I can attach multiple voids to one for instance, while you need a signal per void.

  • @megafonural
    @megafonural 6 лет назад +9

    Thanks for these very useful tutorials. It's a big luck to find something like this in the ocean of "lets make a cube" scrap.

  • @ExileOfBrokenSky
    @ExileOfBrokenSky 4 года назад

    I always come back to this video cause I always forget the details of events and actions, but this video is short, precise, and awesome.

  • @jamesconning5669
    @jamesconning5669 8 лет назад

    Really nice way of laying out multiple scripts for the audience to follow!

  • @diliupg
    @diliupg 4 года назад

    Easily the best explanation about Delegates and Events. Thank you very much.

  • @justinrivera7800
    @justinrivera7800 4 года назад

    I could not understand events for the longest time! You are a god send! Make a Udemy course, the people will come! Thanks!

  • @zincorelearn980
    @zincorelearn980 3 года назад

    Bruh... I've been trying to understand delegates and events for weeks, and you taught me in 15 minutes. Thank you so much, I'm looking for more amazing lessons from you.

  • @bushrhaddad9979
    @bushrhaddad9979 6 лет назад

    This has been saved my life at the past, and gave me the best understanding I've ever had from youtube tutorial.
    Thank u

  • @Kamtrocity
    @Kamtrocity 6 лет назад

    Holy Cow! I just completed a whole project that basically calls methods from and to other scripts! Lesson learnt!

  • @LTSlugg
    @LTSlugg 4 года назад

    Youve earned my Sub, been trying to wrap my head around this pattern for a bit now. Your video has been very precise. Thank you, I am still struggling to understand it and will need to put it in practice to see its full effect.

  • @MohamedOsama-dq9sk
    @MohamedOsama-dq9sk 6 лет назад

    i wish all other youtubers can deliver information like you , thanks man

  • @Paruthi.618
    @Paruthi.618 3 года назад

    One of the best explanations in youtube

  • @TheGaldren
    @TheGaldren 4 года назад +1

    This tutorial is godlike.

  • @filipathtc
    @filipathtc 3 года назад

    Your videos are soooo incredibly good! Thank you!

  • @TheMarrt
    @TheMarrt 8 лет назад

    Very Helpful, i finally see what all the different words are for (event, delegate, Action, Func)

  • @unlockener
    @unlockener 6 лет назад

    Hands down best tutorial on delegates&events.

  • @anubhavnegi4230
    @anubhavnegi4230 4 года назад

    Loved it the way you explained why before how..

  • @bondymagnomous3544
    @bondymagnomous3544 6 лет назад +1

    That was absolutely incredible Sebastian! Good job, love your videos.

  • @Anubis523kds
    @Anubis523kds 7 лет назад

    Thank you so much!!! I'm was working on some stuff, had help from an alumni at school for thesis and I can finally grasp and write delegates and events. Bless you!

  • @SilverMiraii
    @SilverMiraii 7 лет назад

    Quite informative and easy to understand because it wasn't as convoluted as the delegate video , so yeah I finally understand how to actually implement events, at least on a surface level, good enough for now.
    My advice is to strip the code as much as possible, no returns, no arguments at least in the first example, then step it up if you want.

  • @masonmason22
    @masonmason22 3 года назад

    These tutorials are great. Especially the concrete examples. Thank you.

  • @ROXPLAYZONE
    @ROXPLAYZONE Год назад

    Best on the youtube tutorial easy simple with great example ....Loved it 😍😍

  • @MuhZubairAli
    @MuhZubairAli 8 лет назад +5

    You are simply awesome Teacher...

  • @AlexStrook
    @AlexStrook 8 лет назад

    That's the single, most well explained tutorial about delegate I've seen, thanks !

  • @run1946
    @run1946 2 года назад

    SO EXCITED TO SEE THIE VIDEO, You help me solve a big problem,THANK YOU!

  • @VEOdev
    @VEOdev 2 года назад

    Events are the best thing about coding its fun and easy to use and keep code clean

  • @benjaminlehmann
    @benjaminlehmann 2 года назад

    Brilliant. So clear; so helpful. Thank you.

  • @ArmandCloud
    @ArmandCloud 7 лет назад +5

    Thanks for tutorial. feedback : Actions and Functions needs some example.
    Best Regards,

  • @michelekribel2247
    @michelekribel2247 8 лет назад

    Just wanted to say, I really appreciate your channel. Thank you.

  • @nenadsuperzmaj
    @nenadsuperzmaj 2 месяца назад

    "DeathDelegate" - works as an identifier but also as a metal song/band name

  • @yuchen3587
    @yuchen3587 2 года назад

    This is exactly what I wanted! Thanks man

  • @brigandpatrolworllvideos9
    @brigandpatrolworllvideos9 7 лет назад +1

    Great stuff. I'd like another example to really help the concepts sink in, but I'll just get into unity and try it out myself

  • @dwexecutioner
    @dwexecutioner 4 года назад

    This tutorial explains delegates very well, thanks!

  • @rupertwassaner3330
    @rupertwassaner3330 6 лет назад

    To anyone who is interested, there is something called a UnityAction under the UnityEngine.Events namespace that also functions as a void delegate.
    You can read about them here: docs.unity3d.com/ScriptReference/Events.UnityAction.html

  • @themerpheus
    @themerpheus 8 лет назад

    It is really,reaally helpful.I am searching a basic explanation for this subjects.So thank you a lot Sebastian :)

  • @lucastejero6547
    @lucastejero6547 7 лет назад

    Thank you very much to use your time to explain this to everybody, you are so clear

  • @TheXientist
    @TheXientist Год назад

    This vid straight ballin fr fr

  • @stanek
    @stanek 4 года назад

    This was amazing! So beautifully explained. I have subscribed and will now binge :)
    Thanks you so much for taking the time to make this!

  • @SuperBiasedGary
    @SuperBiasedGary 6 лет назад

    Amazing tutorial, explained a complex system so clearly.

  • @SinusQuell_
    @SinusQuell_ 4 года назад +2

    So basically, we are moving the reference, which is still required (just a different one), form the player to the Achievement and UI classes. I don't understand how this makes it any cleaner.

    • @user-jw4nt3qm6q
      @user-jw4nt3qm6q 4 года назад +1

      This makes it cleaner because it is responsibility of Achievement and UI to do something when player dies. So why Player should call functions in other classes?

  • @Byzs
    @Byzs 8 лет назад +19

    You are a great nerd, keep up the gj

    • @roko567
      @roko567 8 лет назад +16

      lmao that's a rather interesting way to compliment someone

    • @victornaut
      @victornaut 8 лет назад +1

      You guys are so funny hahaha

    • @bity-bite
      @bity-bite 3 года назад

      @@roko567 What makes it interesting?

  • @BenPearson_kd7uiy
    @BenPearson_kd7uiy 8 лет назад

    I've long known about Action and Func, it's nice to see how to do this without importing System:-)

  • @SebastianLague
    @SebastianLague  8 лет назад +44

    Hi everyone, I hope this 2-part series has helped you get to grips with delegates and events.
    Let me know what topics you'd like to see covered in the future.
    If you want to translate this video, you can do so here: ruclips.net/user/timedtext_video?ref=share&v=TdiN18PR4zk

    • @purpleice2343
      @purpleice2343 8 лет назад

      I doubt I am the only one who didn't quite understand threading in your terrain tutorials so I think people would like to see callback functions and anything similar to that covered.

    • @SebastianLague
      @SebastianLague  8 лет назад +7

      +Purple Ice Well the callback there is just passing a method into another method, so it's using delegates like last episode. But I do think a video on threading in Unity is a great idea, thanks for the suggestion.

    • @purpleice2343
      @purpleice2343 8 лет назад

      Well I just proved my point that I have no idea about anything related to threading, maybe I am just bad at googling but didn't find anything that would explain it to me, anyway, thanks for considering making a video on it.

    • @Devastus
      @Devastus 8 лет назад

      Good thing you included the explanations for Actions and Funcs, they've somehow eluded me up to this point and should come in handy for several occasions.
      Thumbs up for a separate threading video, it's something I reckon many people would love to understand better since it's a powerful but tricky technique to get working right.

    • @purpleice2343
      @purpleice2343 8 лет назад

      Devastus The problem is, almost everyone knows how it works in general after like 5 minutes of googling, but mastering is hard, and not something you can learn in few days. I don't even know where to start.
      I know that it works separately from main thread, that two threads accessing same thing at the same time can destroy everything and etc, but I have no idea where to start with them. I have followed simple tutorial on "voxel engine" on unity and the last thing I need for it to add whatever I want to it is threading so it stops freezing once in a while and I will be good to go, though I couldn't find ELI5 type of explanation for it so I gave up on that and moved on, for now. Anyway I will start going to university this year so I will learn it either way.

  • @filipv4u
    @filipv4u 8 лет назад +2

    Great videos, a good follow up to this would be a video about UnityEvents and UnityAction.

    • @cadfoot568
      @cadfoot568 8 лет назад

      UnityEvent and UnityAction can be serialized in the inspector. You may notice it on some UI components

  • @zeroblackstar
    @zeroblackstar 4 года назад

    I love creating the func

  • @Kenbomp
    @Kenbomp 2 года назад

    Nice type declaration

  • @lafish4308
    @lafish4308 3 года назад

    this is amazing, thank you so much

  • @dennisgonzales9521
    @dennisgonzales9521 5 лет назад

    Very very awesome video.

  • @hasannagaria1395
    @hasannagaria1395 5 лет назад

    Thank you !

  • @Hydra-tm7qm
    @Hydra-tm7qm 4 года назад

    thanks for the explaintion

  • @stevekingu1760
    @stevekingu1760 4 года назад

    Thank you

  • @danigolmestre
    @danigolmestre 7 лет назад

    Very good. Thanks

  • @luislodosm
    @luislodosm 5 лет назад

    Best explanation I found.

  • @Spukulele
    @Spukulele 8 лет назад

    Really clear videos. Great job!

  • @Victor-oo4ux
    @Victor-oo4ux 4 года назад

    Because a like wasn't enough. Here is a token of my gratitude! :)

  • @nelsonthekinger
    @nelsonthekinger 2 года назад

    great job, still a great vdeo after all this time :))

  • @Xerceth
    @Xerceth 6 лет назад

    Awesome 2-part series : )

  • @bharath_v
    @bharath_v 3 года назад

    Good One!

  • @FuzzyDPozzy
    @FuzzyDPozzy 5 лет назад

    we need a 3rd tutorial for events with actions ,examples on how to use them , like theplayer,ui, that you gave on this one please when u have time it would be nice