Mastering Events in Unreal Engine with C++

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you would love to add events in your game but you are overwhelmed with all the options offered by the Unreal Engine in this video we will go through each one of them let's start with blueprint implementable event and blueprint native event these events actually behave more like virtual functions they are useful in scenarios where a function is defined in C++ but the specifics of the function are implemented on the blueprint s for instance consider the doors in your game as a actor class equipped with a blueprint implementable event function while they all inherit the same foundational function for opening and closing this setup allows each door to customize its opening and closing Behavior according to its specific requirements let's go through the implementation for both of these and see how they are used for blueprint implementable event we just Define a function attach a blueprint implementable event decorator and we are done we can now use this function in C++ like any other normal function but in the blueprint class you can then overwrite the event and do whatever you want inside for blueprint native event we can do the same we create a function and attach a decorator but the neat part is that you can also specify an implementation in C++ this is done by creating another function that has the same name but adds an underscore implementation the C++ code will be called if no up blueprint overrides the event function so let's summarize both events always use these if you want to allow blueprints the ability to override one of your C++ functions moving on to real events when we talk about events we actually mean communication between multiple actors an actor broadcasts an event and other actors subscribe and listen to the event and react to it in C++ this is usually done by using delegates anrea supports multiple delegate types but all of these delegate types have in common that they are declared with a micro here's an example for a simple event we first declare a delegate and give it a name then we can Define multiple parameters for this event depending on the amount of parameters you need to change the declare macro from one par to two pars and so on when you have declared your delegate the usage is super simple you can define a variable with this exact delegate type this variable will be essentially the bridge between your actor and the subscribers in the function where something happens and where the event should occur you just need to broadcast the event with the necessary parameters and you're done now you have created an event that is broadcast to its subscribers but this is just one way to declare an event delegate there are a couple of different delegate types you can either use the standard delegates or multicast delegates and you can either use use non-dynamic or dynamic delegates the usage depends on what you actually want to do in most cases you will probably want to use multi delicates as it supports multiple subscribers but there are some cases where it can make sense to restrict the event to just one subscriber for dynamic and non-dynamic versions it again depends on the usage Dynamic events are serialized in the engine that means your blueprints can subscribe to your C++ events and listen to them the non-dynamic version of only support C++ functions but it also supports more advanced concepts like lambdas the benefit of the dynamic version is clearly that you can use blueprint subscribers but for the cost of performance here is how you create the dynamic version of a multicast delegate as you can see it is not very different the main difference is the word dynamic and that you need to give the parameters a name this is necessary so the blueprint can show you a name for the parameter when you de cleare the event variable you should also use a U property with blueprint assignable so your event will appear in the details tab of your blueprint class okay let's see how a subscriber could listen for your events and react to it let's first check the non dnamic event subscribe to it by using the at you object function it takes a pointer to the object and a function reference of the function you want to call when the event occurs you can also subscribe to the event by using a Lambda function a Lambda function is a simple way to subscribe to an event without going through the function setup in the header file for dynamic events you can unfortunately only use at Dynamic this is pretty much like the at you object function but unfortunately for dynamic events you are not allowed to use Lambda functions this is one drawback of dynamic events I hope this video helped you understand events in C++ if you have any questions or want to see a more thower example just write it in the comments so have a nice day and see you later
Info
Channel: Scripted Adventure
Views: 5,435
Rating: undefined out of 5
Keywords: events, c++, unreal engine, ue5, delegates, tutorial, gamedev, game development, ue, multicast, dynamic delegates, blueprintimplementableevent, blueprintnativeevent, blueprint, native, implementable, game design patterns, programming pattern, pattern
Id: gDyc0hn_HM4
Channel Id: undefined
Length: 5min 17sec (317 seconds)
Published: Sun Jan 21 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.