Unreal Engine Interaction - Event Dispatchers tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so the last thing that I want to show you is how you can do because we've been talking a lot about how to communicate like make actors communicate to each other sending messages uh through different things and receiving messages so one of the things that I I'd like to mention in the in the end are are things that are called event dispatchers so event dispatchers are another way of uh just kind of communicating data and allowing or communicating events uh so basically what they do is that they uh they allow you to listen to events on other things uh so that so you can react to them so it's made me a little bit the the other way around than we've been doing before so I'm gonna make a small change to the way that this works uh here I'm going to go into the third person character again and we used to make it so that whenever we clicked something we called do the jump but what I'm going to do is I'm going to go in here and I'm going to do a a new event and I'm going to call it uh destroy the bouncing ball uh so the goal here is and just to do the uh do the logic I'm going to call destroy actor so this is gonna do what this is gonna do is uh and instead of calling do the jump here on the uh on the boundary I'm gonna call destroy uh not destroy actor but I'm going to just destroy the bouncing ball so uh now when we play whenever I click something uh it's gonna get destroyed uh from the world okay uh so that's kind of cool so now we have something similar to uh like it's uh it could be a game uh and let's go into the bouncing ball here but what we want to do before we destroy the actor uh we wanna maybe notify uh anyone uh it doesn't really matter who it is we want to notify we're going to send out a message saying I am being destroyed so that other kind of other actors and other things can actually react to it so here on the left I'm gonna do an event dispatcher and I'm gonna call it on uh I was asked to be destroyed and I'm going to drag it in here and I'm gonna call it so you can see that this little uh letter here this means that this is just a message we don't know if anyone is listening to the message or anything like that this is just kind of a courtesy thing from this actor saying all right so here is something that's happening to me that someone else might be interested in uh so uh so yeah basically uh what happens now is that nothing is going to change uh the actors here are being uh kind of destroyed one by one so uh the question is then how do we use these uh these event dispatchers and this is where uh things are going to get a little bit complicated and this is something that took me a lot of time to figure out so uh if you uh if you can follow along with this and if you get this uh you're reaching a pretty high level of group blueprint programming so in the bouncing ball blueprint uh what I'm gonna do is on begin play uh on begin play I'm gonna say uh get all actors of class here I'm gonna get the uh BP underscore bouncing ball so each instance of the bouncing ball blueprint is gonna fetch all of the other ones uh I'm gonna oh I'm gonna see if I can bind on uh yeah okay so I can actually I can actually do it like this so uh this is uh this is kind of nice I can do this with the uh with the array so I want to know uh I want to know each one of the bouncing balls wants to know if any other bouncing ball got destroyed uh and this is a little little hard to wrap your head around so I'm gonna say someone was destroyed all right so if I if I go ahead and I print this here I'm gonna say uh I'm gonna do get self uh this is going to be a reference here to the blueprint that we're in and I'm gonna do get display name so I'm going to get my name here and I'm gonna say uh do a couple of uh and this is probably the most advanced thing uh that we're doing I'm gonna do format text so I'm going to say I am and then I do the curly braces and I'm going to say me just noticed that someone got destroyed and I'm gonna plug this into me and then I'm gonna plug this here so uh basically what's gonna happen now that whenever anything is destroyed from the world uh anyone who has has this event bound is going to like uh it's gonna get notified so if I press here and I click here you can see that as the open of the lock here I am the fir the first ball I am the first ball five and I just know that someone got destroyed so you can see that every single ball that we have is saying that oh I just realized that someone else got destroyed I don't know who got destroyed but I just know that there's an event that happened and I'm listening for this event so each one of these is printing the message and they're saying someone got destroyed so what we can do now is we can go into the bouncing ball here and we can go into the event and we can add an input to the event the input is going to be BP bouncing ball and I'm just going to call it who and now I have to go in and refresh this here uh okay so now you can see that uh when we are destroyed and you can see that this can be really confusing because we're working in the same blueprint so here we're saying that if someone calls destroying the bouncing ball it calls this event and it needs to know uh who who was destroyed so I'm gonna do self because uh so if someone asks this ball to be destroyed it's gonna say okay I'm gonna broadcast this event I'm gonna dispatch an event into the world I'm gonna say I got destroyed and then I'm gonna say and then I'm gonna be destroyed okay so uh so now we have uh and then here on begin play we were also saying I am interested in all of the bouncing balls in the world I'm interested in knowing if if one of them was destroyed and um uh and yeah and then I get a message here saying who was destroyed so I'm gonna expand this here I'm gonna say instead of saying someone I'm gonna change this into uh who and I'm going to say I am here and I just noticed that who got destroyed so who get this play name and this gets plugged into here so now that we play uh it's gonna clear this you should be able to see that when I clicked this one here every single ball Here I Am the first ball five the second ball first ball like these are just the names of the balls here they're called first ball on the second part because we duplicated them earlier and I noticed that the second ball five just got destroyed all of them are getting a message that the second ball five just got destroyed even uh the second ball five it and it gets a message saying I just got destroyed and here is something that we can do with this we can say that if not equals if who is not equals myself because we don't want to uh to do anything on myself we can say get self uh we don't have to do that we're gonna do get uh we're gonna do set skate set after scale into cat after scale 3D we're going to multiply this by let's say yeah this is fine multiply this by 0.90 so we're going to say set the scale to ninety percent of what you were and now we have we have some cool blueprint logic now I may have to open up some new blueprint area real estate here okay so what's happening now is that anytime that the bouncing ball gets a message saying that someone got destroyed we're gonna lower we're going to reduce the scale of it uh to 90 of the scale that it was before okay and then we're going to print the message here and then we do uh to jump do the jump we do uh we may we get a little bit smaller and then we do a jump four hour destroyed uh brethren okay so here once we click this all of the balls jump and all of the balls get a little bit smaller uh each time and you can actually see that they're jumping higher each time because their mass is getting smaller and smaller and smaller uh with the size uh so now uh now we've basically set up the most uh one of the more simple uh well not necessarily simple but we set up an event dispatcher where uh all of the balls actually keep track of all of the other balls and they can react for a react to a message for when I click it you can see that uh they do something so uh so yeah this was the this is an intro to the uh to the event dispatchers and how you can communicate with actors between those
Info
Channel: Gisli's game development channel
Views: 5,098
Rating: undefined out of 5
Keywords:
Id: 8Vyy4SJlXiY
Channel Id: undefined
Length: 10min 28sec (628 seconds)
Published: Fri Mar 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.