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.
"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.
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
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.
+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.
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.
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.
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.
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
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.
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.
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
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!
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!
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!
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!!!
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!
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!
"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
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!
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.
@@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-
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.
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.
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
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!
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.
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.
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.
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
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.
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?
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.
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!
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?
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
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?
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.
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?
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.
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?
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?
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)?
+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.
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.
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.
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.
Thank you!
This exactly, i wanted to write something similar, but i am not at all surprised that other viewers agree. Very informative tutorials!
"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.
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
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.
+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.
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.
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.
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.
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
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.
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.
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.
Thank you
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
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!
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!
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!
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!!!
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!
0:17 that went dark real quick i love it
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!
"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
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!
2:32 now you can do deathEvent?.Invoke(); instead of checking null with if.
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.
@@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-
@@imSoCalamari awesome. Thanks so much for the info.
@@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.
This is called Null-conditional operators (?.) if anyone wants to look it up, it's available in C# 6 and later.
I come here once a month to refresh the details between delegates/actions/funcs, and I have to say, thank you so much :)
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.
You are a very gifted individual Sebastian Lague
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.
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
As a noob game dev, this really helped me understand these intimidating concepts. Thank you so much Sebastian.
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!
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!
Can't say enough how this tutorial is so much better than all the other c# event tutorials I've seen on YT.
Thanks much! I watched several videos and documentation, but never fully understood how to use delegates and Events until this vid. Thanks again.
You are a legend, I am getting amazed every time I watch one of your videos.
This made me understand delegates better than any resource i've studied. This deserves more views!
Sebastian Lague, i learn so much in your vids... Thank you!
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!
+J Herlache I'm happy to have helped!
I was struggling for 2 days to figure out delegates and events, these two videos finally made it all click!
Six years on and this is a timeless classic =)
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.
Man, this dude's tutorials are S tier, best I've found in a long time
Best tutorial on delegates around. Cheers Sebastian :)
WOW! It became clearer in 6 minutes than in one and a half hour of lecture at my university.
Thanks!
Easily the best explanation about Delegates and Events. Thank you very much.
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.
Holy Cow! I just completed a whole project that basically calls methods from and to other scripts! Lesson learnt!
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.
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.
Hands down best tutorial on delegates&events.
Really nice way of laying out multiple scripts for the audience to follow!
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
Best tutorials i have ever seen about coding
The most excellent coverage on this topic. Thank you!!!
Very Helpful, i finally see what all the different words are for (event, delegate, Action, Func)
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.
you are awesome bro, thank God that people like you exist on earth!
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?
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.
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.
i wish all other youtubers can deliver information like you , thanks man
These tutorials are great. Especially the concrete examples. Thank you.
Thanks for tutorial. feedback : Actions and Functions needs some example.
Best Regards,
This has been saved my life at the past, and gave me the best understanding I've ever had from youtube tutorial.
Thank u
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!
Loved it the way you explained why before how..
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?
I could not understand events for the longest time! You are a god send! Make a Udemy course, the people will come! Thanks!
Events are the best thing about coding its fun and easy to use and keep code clean
This tutorial is godlike.
That was absolutely incredible Sebastian! Good job, love your videos.
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
One of the best explanations in youtube
You are a great nerd, keep up the gj
lmao that's a rather interesting way to compliment someone
You guys are so funny hahaha
@@roko567 What makes it interesting?
This tutorial explains delegates very well, thanks!
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
Just wanted to say, I really appreciate your channel. Thank you.
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?
That's the single, most well explained tutorial about delegate I've seen, thanks !
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.
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?
Thank you very much to use your time to explain this to everybody, you are so clear
Your videos are soooo incredibly good! Thank you!
I've long known about Action and Func, it's nice to see how to do this without importing System:-)
Best on the youtube tutorial easy simple with great example ....Loved it 😍😍
Amazing tutorial, explained a complex system so clearly.
Great videos, a good follow up to this would be a video about UnityEvents and UnityAction.
UnityEvent and UnityAction can be serialized in the inspector. You may notice it on some UI components
Brilliant. So clear; so helpful. Thank you.
But I wonder something. Is it possible for the class that has the delegate or event to unsubscribe all functions on a delegate?
Could you make a video about lists and dictionaries?
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.
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?
It is really,reaally helpful.I am searching a basic explanation for this subjects.So thank you a lot Sebastian :)
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?
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)?
+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.
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.
This is exactly what I wanted! Thanks man
Great example of the why and how of events. BTW, is your vs colour scheme available on StudioStyl.es?
Why are you so good.
This was amazing! So beautifully explained. I have subscribed and will now binge :)
Thanks you so much for taking the time to make this!
You are simply awesome Teacher...
This vid straight ballin fr fr
OMG YEA how would you make a faceted version of the procedurally generated terrain?
SO EXCITED TO SEE THIE VIDEO, You help me solve a big problem,THANK YOU!
"DeathDelegate" - works as an identifier but also as a metal song/band name
Best explanation I found.
Because a like wasn't enough. Here is a token of my gratitude! :)
I love creating the func
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.