In this lecture, we'll learn about delegates and event handlers and how they work together. We'll start by talking about what delegates are. Delegates are a type that specifies a method signature. And that may sound really confusing to you, so let's think about it this way. We could have a delegate type that says, this method has one integer parameter. And we could have another delegate type that says, this method has two string parameters. That's all we're talking about, is the method signature, and the delegate that says here's what that method looks like. The C# documentation says delegates are like C++ function pointers, but they are type safe. And that means nothing to you perhaps, especially if you've never programmed in C++. So let's think of it this way, a pointer is like a reference. And we know that we can have references to objects in memory, that's what classes are, right? They're reference types. And so we can refer to an object in memory, and really what we have is the address of where that object is. Now, it turns out that memory holds both data and code, and so we could also have the address of, or a reference for, a particular method, and that's what delegates are. They're sort of like a pointer to a particular method. Now the big idea, the thing that's great is that delegates let us pass a method into another method. And sort of pause for a moment and think about that. We know how to pass arguments into methods. We've passed numbers and objects and all kinds of stuff. But a delegate lets us pass a method into another method. Here's why that's so powerful. It lets us do something like, here, I'm giving you me as a method, and if something interesting happens, call me. That's kind of what the event system works like, and so delegates are a key piece because it lets us pass a method into another method. So that we get called when something interesting happened. Now's a good time to go do an in-video quiz about delegates. I promised we'd also talk about event handlers. So what are event handlers? Well, simply stated, an event handler is a method that responds when an event occurs. And put another way, it's just a delegate that has indicated that it is interested in hearing about this event when it happens. Let's look at a pictorial representation of how well this works. So here we have a big hunk of event on the upper right and we have an event handler on the left that said, I am interested in this event. So, it's called a particular method on the event. Usually, that's called AddListener at least in the Unity environment. So it basically says, add me as a listener for this event and because the event handler is a delegate, it can pass itself. And the event object stores this information and says, well, if I actually fire, then I am going to call this particular method who said they were interested when my event occurs. Same with the event handler on the bottom right. That event handler has also said I'm interested in this event, add me as a listener as well. The event handler on the lower left has not registered to listen for this particular event. They may be an event handler for some other event, but not for this one. Okay, so that's the first linkage, right? The event handlers tell the event, hey, I want to know if this event happens. When the event happens, the event calls or invokes each of the methods, the delegates, that said they were interested in the event. And so this is a way for the event to call those methods back and say, hey, I just happened. Do what you will without information, and that's really conceptually the way event systems work in generally and, certainly, the way the event systems that we implement in our unity games will work. To recap, delegates let us pass references to methods. And that's useful to us because event handlers that match your particular delegate type can call the AddListener method, for a particular event and say, I'm interested in this event. Please let me know when it happens. And the event, when that event occurs, can then invoke each of the methods that said they were interested in the event because they added themselves as listeners. And that, in a nutshell, is they way event systems work.