Petty nice tutorial mate! I've got a question about delegates that maybe you can solve... If for any instance of BP_GrowingThing you have to select the instance of BPEnemy that they are tracking, isn't this like the oposite of event driven functions? I mean, whats the diference between this and: Add to the enemy class a reference to a GrowingThing and every time it shoots do GronwingThingWatched->Grow(); Am I missing something here? Thank you in advance tho!!!!
Thw reason to use delegates instead of directly using functions is because of 3 reasons : 1. Every instance can have different actors listening to it so 1 enemy might have an actor listening thatll grow when it attack, another might have something listening thatll jump instead, and one thatll move, and one thatll become visible/invisible and so on. By using a delegate, different instances can have different kinds of listeners with totally different effects. 2. And more importantly, if you have 20 different classes listening to different instannces of your actor with the delegate (enemy class in this example), those listeners have to be aware of the contents of enemy class, but enemy class doesnt need ti be aware if the contents of whoever is listening, al it needs to know is that it calls out "hey, i did thing" and then amyone listining for that will do their response. That means the enemy class doesnt need to now #include every possible class that could listeb to it, which you would need to do if you made enwmy call functions directly on those listeners. 3. You can easily add listeners and remove them during gameplay. So lets say you have a button, when you press it, the "grow actor" adds itswlf as a listener to the closest enemy, thats really easy to do here without havibg to hard code a bunch of if statement so all together it makes for more flexibility and better scaling if you decide a new type of actor you made also should do something when Enemy calls out. Of course, on top of that youre also not limited to just the delegate on Enemy, if you want an actor to run a certain function when one if a few things happens, it can listen to multiple actors, different classes whatever you need it to do.
@@thegamedevcave Looking forward to it. I always learn something from different videos on a same topic, and then add the new info in my document, like a program vampire
Hey! Not totally related to the video, but when I am trying to DECLARE_DYNAMIC_MULTICAST_DELEGATE it gives errors with intellisense. It still compiles just fine, but these intellisense errors are really annoying. How did you get your visual studio to ignore those or correctly detect that it is valid?
i get error lines under my code more often, usually if those liens are not actually errors, they go away when compiling the code, if they ARE actual errors, it becomes apparent during compiling when it throws the error and tells you what's wrong. Hardly ideal but Personally i've gotten used to it by now.
Great tutorial, whats the difference between: DECLARE_MULTICAST_DELEGATE_OneParam DECLARE_DYNAMIC_DELEGATE_OneParam DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam One is without dynamic keyword, and one is without multicast keyword
it's a bit bothersome for me to type out in a youtube comment but the unreal documentation has a few pages on it (which should really link to eachother, but they don't so i'll give you all the links) docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Delegates/ docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Delegates/Multicast/ docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Delegates/Dynamic/
Fantastic video, very well explained. Thank you
Glad it was helpful!
Petty nice tutorial mate!
I've got a question about delegates that maybe you can solve...
If for any instance of BP_GrowingThing you have to select the instance of BPEnemy that they are tracking, isn't this like the oposite of event driven functions? I mean, whats the diference between this and: Add to the enemy class a reference to a GrowingThing and every time it shoots do GronwingThingWatched->Grow();
Am I missing something here?
Thank you in advance tho!!!!
Thw reason to use delegates instead of directly using functions is because of 3 reasons :
1. Every instance can have different actors listening to it so 1 enemy might have an actor listening thatll grow when it attack, another might have something listening thatll jump instead, and one thatll move, and one thatll become visible/invisible and so on. By using a delegate, different instances can have different kinds of listeners with totally different effects.
2. And more importantly, if you have 20 different classes listening to different instannces of your actor with the delegate (enemy class in this example), those listeners have to be aware of the contents of enemy class, but enemy class doesnt need ti be aware if the contents of whoever is listening, al it needs to know is that it calls out "hey, i did thing" and then amyone listining for that will do their response. That means the enemy class doesnt need to now #include every possible class that could listeb to it, which you would need to do if you made enwmy call functions directly on those listeners.
3. You can easily add listeners and remove them during gameplay. So lets say you have a button, when you press it, the "grow actor" adds itswlf as a listener to the closest enemy, thats really easy to do here without havibg to hard code a bunch of if statement so all together it makes for more flexibility and better scaling if you decide a new type of actor you made also should do something when Enemy calls out. Of course, on top of that youre also not limited to just the delegate on Enemy, if you want an actor to run a certain function when one if a few things happens, it can listen to multiple actors, different classes whatever you need it to do.
Thank you for this. Well explained. Your effort has saved me hours.
Glad to hear it!!
Thanks man, i did not knew that the function parameter needs to be the same as declared for the delegate. That solved my issue!
This is the best explanation I've seen on delegates! Thanks!!
Really helpful video, thanks for making it!
Nice work! Have you covered interface yet? I feel like you could make one right after this video, since they are very alike.
got a video about blueprint interfaces lined up for in a couple of weeks :)
@@thegamedevcave Looking forward to it. I always learn something from different videos on a same topic, and then add the new info in my document, like a program vampire
Hey! Not totally related to the video, but when I am trying to DECLARE_DYNAMIC_MULTICAST_DELEGATE it gives errors with intellisense. It still compiles just fine, but these intellisense errors are really annoying. How did you get your visual studio to ignore those or correctly detect that it is valid?
i get error lines under my code more often, usually if those liens are not actually errors, they go away when compiling the code, if they ARE actual errors, it becomes apparent during compiling when it throws the error and tells you what's wrong. Hardly ideal but Personally i've gotten used to it by now.
thank u
Great tutorial, whats the difference between:
DECLARE_MULTICAST_DELEGATE_OneParam
DECLARE_DYNAMIC_DELEGATE_OneParam
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam
One is without dynamic keyword, and one is without multicast keyword
it's a bit bothersome for me to type out in a youtube comment but the unreal documentation has a few pages on it (which should really link to eachother, but they don't so i'll give you all the links)
docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Delegates/
docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Delegates/Multicast/
docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Delegates/Dynamic/
@@thegamedevcave Thanks a lot for the links! Didnt know there was much differences.
This was very useful! Thanks again!
You're very welcome!
👌