Event Dispatcher - The Basics Of Nodes In Unreal Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another episode of the basics of nodes in unreal engine today we're going to be going over event dispatchers so i have made a video on this previously where i made something using event dispatchers and kind of explain them a little bit similarly to how i did it with blueprint interfaces but this is going to be a bit of a more in-depth and specific one just purely for event dispatchers what they do how they work and all that great stuff so event dispatchers are a nice simple and efficient way to fire up events and or communicate within different blueprints so you can create and bind event dispatchers then when you call it like you do with a normal function or macro custom event another event which you binded it to will fire off so i think the best way for me to show this off and for you to understand it is to just get into unreal and show you a working example and seeing it in action so we're here in unreal and the example i'm going to go for is firing off an event in the level blueprint from the player blueprint now this is useful because ordinarily you couldn't do this as you can't actually cast to the level blueprint so what i'm going to do is i have this blocking volume here or an invisible wall just in front of the staircase now obviously the player can walk around it or they can jump up here again this isn't really for functionality this one here is just an example to show you how it works like i said i want this to fire off from the character blueprint so that's where i need to make this so i'm going to open up my character blueprint here and you can see in the bottom left we have event dispatchers i'm going to hit the plus event dispatcher and i'm going to name this one remove wall because what i want to do is remove that blocking volume or that invisible wall when we reach a certain level and as you can see here this is also how i'm leveling up the player simply when they press two on the keyboard it's going to increase their level by one again you probably want to set this up differently but this is the fundamental code of it so you understand how it works because what i'm also going to do is i'm going to be checking the place level in the level blueprint you'd probably want to do that in here in this character blueprint again i'm showing you how to do it in the level blueprint just to show how you can pass through variables using the event dispatchers so you can take this level float here and move it into the level blueprint which again you normally wouldn't be able to do so we need to call this dispatcher when we want it to fire off and again i want to do this when i level up so i'm going to drag and drop my remove wall into the event graph and we want to hit call because we want to call this so that it will fire other things off like you'd call a function to fire off the function or a macro or anything like that it's the same with event dispatcher and we're going to connect that into here because i wanted to just fire off straight away what i'm also going to do is that something i forgot is i want to actually pass the level variable through here don't i so i want to select the remove wall event dispatcher and up in the top right we have inputs i'm going to hit the new parameter here and i'm going to name this one level and it is already a float for me which is what i want and we can very simply just connect up the level into there like so compile and save and now what's going to happen is when we press two the player is gonna level up and is going to call this event dispatcher like so inputting the correct level into there and when we call it we're essentially broadcasting a message across the whole game into any other blueprint which is listening for this so now we need to set up the blueprints which are going to be listening for this event dispatcher to then fire off other code when this is called so again i want to do this in a level blueprint so i'm going to go over to my third person example map level blueprint here and you can see i've already got event begin play cast on my character and you do want to make sure that on event begin play you are casting to the blueprint where you have this event dispatcher stored so again mine is in a third-party character and as that blueprint what you want to do is bind event 2 and then whatever you named that dispatcher so i named mine remove wall like so now you can see we have the bind event 2 and we have a nice little event note there i'm going to drag out the event and add a custom event and i'm going to name this one remove wall ce for custom event and you can see in this custom event we now have this level here so what's going to do is when we call this removal event dispatcher it's going to then fire off this custom event here because we have binded the event to that dispatcher so when it fires off the event will also fire off and we now also have that variable that we inputted into it now coming out of this custom event for us to use so what i want to do is simply just hold down b left click to get a branch to check what the player's level is so i'm going to get a greater than or equal to and i'll set it to 5 so the player has to be level 5 or above and if that's true i'm going to simply play a sound and then remove that wall so i get a play sound 2d for a test i'll use camera shutter and then to remove the wall i need to select it and just drag and drop the blocking volume into my level blueprint and destroy actor and that is why i'm doing it in the level blueprint because you can't get a reference to this inside of other blueprints it has to be the level blueprint so that last bit might have been a bit quick but that's because you don't need to understand that for the dispatcher this is just the code i wanted to fire off so again when i press two i'm gonna level up and fire off the event dispatcher inputting our current level and when that dispatcher is called it's gonna fire off this event here because we have binded the event to that dispatcher so that broadcasts this listens and then when it fires off this event will also fire off getting that level float and using that here where i want it so i can hit play and test this out we go over here i can't walk up the stairs because the blocking volume i'm constantly holding w i press two and we're gonna level up once twice three times four times and when i press it this time it should work five you can see we got sound effect and we walked through as it got removed like so so that is working perfectly for us we have an event dispatcher in our character blueprint which we're calling when we press 2 and we're passing through a float variable as well into our level blueprint which we can't normally cast to and we're firing off an event based on something in our character blueprint also passing through the float variable there as well so i hope that example helped you to understand it so again event dispatchers are a much more efficient way of firing off events especially more than one at a time because when an event dispatcher is called it will simultaneously fire off all the events that are binded to it plus we can pass variables through this and communicate with different blueprints for example the level blueprint which you can't ordinarily do because like i say you can't cast to a level blueprint so this is much more efficient than casting methods similarly to blueprint interfaces are as well but blueprint interface just does something slightly different to the event dispatcher this is more for firing off events the blueprint interface is more purely for just communicating and firing off functions instead of events so the blueprint with the dispatch in will broadcast a message and the other blueprints where this event dispatch is binded to different events is going to listen to that message and as soon as they hear it they're going to fire off the events that are binded to it so therefore it will fire off the appropriate code what you want it to do so again it's a much much more efficient way to what most people do for example event tick and casting this is much better but i think that'll be for the video on explaining what the event dispatchers are again it's quite a simple explanation so i hope you understand it a bit more than you did before if you did let me know in the comments down below and if you didn't also let me know and i'll try and help you understand it a bit more with maybe some different examples as well so thanks so much for watching again i hope you enjoyed and i hope you found it helpful and if you did make sure to like subscribe down below so thanks so much for watching and i'll see in the next one [Music]
Info
Channel: Matt Aspland
Views: 16,401
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, how to, ue5, unreal engine 5, execution, what is the, explain, explanation, of, the, node, nodes, basics, basic, in, series, playlist, how to use a, how to use, blueprints, use, to, how, when, quick, easy, integer, times, amount, input, inputs, it, get, all, with, actor, actors, blueprint, class, out, copy, event, dispatcher, dispatchers, communicate, level, levels, cast, cast to level blueprint, variables, float, value, values, between, efficient, call, bind, fire, off, execute
Id: xHISTuyhHTM
Channel Id: undefined
Length: 7min 25sec (445 seconds)
Published: Thu Jun 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.