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

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

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

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

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

  • @rkpixeldesign
    @rkpixeldesign 11 месяцев назад +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

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

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

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

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

    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!

  • @glebpalchin6809
    @glebpalchin6809 8 лет назад +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!

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

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

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

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

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

    0:17 that went dark real quick i love it

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

    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!

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

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

    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!

  • @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 3 года назад

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

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

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

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

    You are a very gifted individual Sebastian Lague

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

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

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

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

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

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

    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!

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

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

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

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

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

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

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

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

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

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

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

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

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

    Six years on and this is a timeless classic =)

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

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

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

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

    Best tutorial on delegates around. Cheers Sebastian :)

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

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

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

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

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

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

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

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

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

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

    Hands down best tutorial on delegates&events.

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

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

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

    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

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

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

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

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

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

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

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

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

    Hey, I love these videos, they have made the concepts much clearer to me. I do have a random question related to the IDE. At around 2:36, I noticed that the if statement's second bracket } wrapped around the execution code automatically, how was that done?

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

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

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

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

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

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

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

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

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

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

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

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

    Loved it the way you explained why before how..

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

    Maybe I miss something here but in the shown example the subscribing classes to not know which player has died. So In an RTS where one would have lots of units and one would like to sound an alarm if a unit gets attacked or a message with it's position shown.. the messenger class would have to subscribe to every unit and the delegate would need a parameter referencing the unit? If so you would need to tell the massager of a new unit to subscribe to? Or is there an easier way?

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

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

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

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

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

    This tutorial is godlike.

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

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

  • @brigandpatrolworllvideos9
    @brigandpatrolworllvideos9 8 лет назад +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

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

    One of the best explanations in youtube

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

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

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

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

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

    Hey Sebastian,
    I think this an excellent series that more folks should know about. Thanks for effort you put in. I'd like to read up a bit more about the Func delegate since i don't quite get the return semantics. Could you perhaps provide me with a link to a resource where i could read up on the subject please?

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

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

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

    • @АнатолийКошелев-э6ч
      @АнатолийКошелев-э6ч 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?

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

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

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

    Your videos are soooo incredibly good! Thank you!

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

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

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

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

    Amazing tutorial, explained a complex system so clearly.

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

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

    Brilliant. So clear; so helpful. Thank you.

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

    But I wonder something. Is it possible for the class that has the delegate or event to unsubscribe all functions on a delegate?

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

    Could you make a video about lists and dictionaries?

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

    Events are so handy. Do you know how they function under the hood? Curious to know if there's any hit for using them too much over direct reference. Not that I can imagine there being much, just curious.

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

    My only question is why should I unsubscribe the OnPlayerDeath methods to the delegate. If I want the methods to be called every time my player dies would it not be better to keep the methods subscribed?

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

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

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

    Good tutorial! I want to make a generic trigger that can fire of Events from EventManager depending the string arguments its given. How can I access these eventmanagers functions via string from a MonoBehaviour?

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

    Thank you for doing these videos they're a great help to me as someone who has very little coding experience. I'd like to further my understanding in the subject, but unfortunately until next year at my school no formal class is offered on the subject. If you don't mind me asking how did you learn to code and are there any resources that you would recommend to someone starting out (besides your own of course)?

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

      +Andrew Phipps Hi. I didn't follow a very structured path when learning to code - for the most part I would think of small games I wanted to make, and then google around whenever I ran into a problem. As for resources, the brackeys channel has some good beginner-level content, and catlikecoding has some fantastics text tutorials.

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

      Hey, thanks for responding! Sounds like what I've been doing for the past few months. I actually started out watching Brackeys to learn Unity, he has some really great content and I will definitely check out catlikecoding.

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

    This is exactly what I wanted! Thanks man

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

    Great example of the why and how of events. BTW, is your vs colour scheme available on StudioStyl.es?

  • @Sikari_08
    @Sikari_08 Месяц назад

    Why are you so good.

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

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

    You are simply awesome Teacher...

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

    This vid straight ballin fr fr

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

    OMG YEA how would you make a faceted version of the procedurally generated terrain?

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

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

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

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

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

    Best explanation I found.

  • @Victor-oo4ux
    @Victor-oo4ux 5 лет назад

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

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

    I love creating the func

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