UE4 c++ Event Dispatchers syntax

  Рет қаралды 28,722

Matthew Hennegan

Matthew Hennegan

8 жыл бұрын

How to set up event dispatchers in c++
*Note* Knew I was forgetting something at the end there, this also lets it work perfectly with blueprint, so if you have a reference to whatever actor the dispatcher/delegate is declared on, you can bind to it in blueprint like normal.
Syntax for copy paste:
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FYourDelegateType, VarType, VarName);
UPROPERTY(BlueprintAssignable, Category = "EventDispatchers")
FYourDelegateType YourDelegateName;
How to call:
YourDelegateName.Broadcast(YourParameters);
How to assign/bind:
ActorWithDelegate(point)YourDelegateName.AddDynamic(this, &YourClass::YourFunction);
Note (point) because I can't put greater or less than signs in the description. Also 'YourFunction' needs the same function signature as the delegate.

Пікірлер: 40
@ReaverPS
@ReaverPS 8 жыл бұрын
really like how you explain things - quick and clear; and maaan, that surely was much easier to understand than from ue docs; thanks!
@matthewhennegan839
@matthewhennegan839 8 жыл бұрын
+ReaverPS Thanks!
@pratyushbsingh5995
@pratyushbsingh5995 7 жыл бұрын
ReaverPS yea theyve made delagates in the docs pretty dense
@Khross30
@Khross30 6 жыл бұрын
Seriously, I tried to understand their docs but eventually my eyes just glazed over...
@m0rph3u5.
@m0rph3u5. Жыл бұрын
Truely Epic!! I've been trying to wrap my head around the documentation explanation and example and still struggling despite being capable of using Evnet Dispatchers in BP.. Thanks alot for this very informative well structured video, short and to the point.
@dragonzlayre4238
@dragonzlayre4238 4 жыл бұрын
Just what I needed! It is really good when you have an object (child) that is inherited from another object (parent). Now my child can talk to its parent. ;)
@bersK00
@bersK00 3 жыл бұрын
For direct parent to child communication it might be better to use references instead.
@elsnowman123
@elsnowman123 Жыл бұрын
Incredible video. Straight to the point. Thanks!
@Jonathanlambert-art
@Jonathanlambert-art 6 жыл бұрын
It's short, concise, and easy to understand. Thank you!
@matthewhennegan839
@matthewhennegan839 6 жыл бұрын
Thanks for the comment! Glad you found it useful :)
@rfw77591
@rfw77591 7 жыл бұрын
thanks a lot Matt, very useful tutorial, straight and to the point!
@arjunjain7773
@arjunjain7773 3 жыл бұрын
Very useful and I understand Dispatchers a lot better now
@codezeeroify
@codezeeroify 7 жыл бұрын
a very simple and a clear explanation, wish upload more vids . thanks !
@dmdmdm_
@dmdmdm_ 8 жыл бұрын
Thanks a lot for your tutorials. They help a lot with getting my c++ project going.
@matthewhennegan839
@matthewhennegan839 8 жыл бұрын
No worries, thanks for taking the time to comment, much appreciated.
@inakidiez5428
@inakidiez5428 2 жыл бұрын
I know this isnt updated but it still helped me a lot. Thanks
@thephysicist989
@thephysicist989 2 жыл бұрын
Thank you so much for this video! Theres very few videos out there with advanced c++ topics in Unreal Engine
@GeNN18192
@GeNN18192 2 жыл бұрын
Thank you in 2022, still not much resources around for UE C++ event system!
@pirofagista
@pirofagista 7 жыл бұрын
Though Epic documentation is pretty good, sometimes they are incompletes or a little fuzzy, so thanks for sharing a video example, that helps a lot who's starting.
@jellyfith
@jellyfith 5 жыл бұрын
Awesome explanation thank you
@soumikbhattacherjee6430
@soumikbhattacherjee6430 4 жыл бұрын
Thank you verymuch. Its worked on 4.22
@prezadent1
@prezadent1 6 жыл бұрын
Please make the code a little smaller, I can still make out some parts of it.
@Evigmae
@Evigmae 5 жыл бұрын
lol, i tried to watch this on a phone.
@GiraffePi
@GiraffePi 7 жыл бұрын
quick and awesome!
@matthewhennegan839
@matthewhennegan839 7 жыл бұрын
Thanks!
@ryanfrank4299
@ryanfrank4299 7 жыл бұрын
Awesome video. One little problem I ran into and maybe its just me but I was placing the Syntax above a UStruct that I was using as the variable. Took me a while to have that light bulb moment to move it just above the UClass.
@matthewhennegan839
@matthewhennegan839 7 жыл бұрын
Ahhhh yes. It does have to be declared before you can use it, I don't think I specifically mentioned that. Glad you got it figured out in the end though.
@digitalmessiah7325
@digitalmessiah7325 3 жыл бұрын
Still relevant. thx ;)
@edbeable2659
@edbeable2659 2 жыл бұрын
hey there. Firstly - great tutorial it all makes sense after weeks of going round in circles having no luck grasping the concept of a delegate / event dispatcher, however I'm having issues, im doing a similar thing where once a checkpoint cleared, it fires the event to a tracker class, loosely based off the unreal tutorial checkpoint tutorial which im recreating in c++ - my delegate is firing fine when activating other functions within the same class / cpp file but when a gate is cleared. but when casting from another class, it crashes on launch. Do you offer private sessions where you may be able to provide some assistance?
@OfHollowMasks
@OfHollowMasks 7 ай бұрын
Is there a safe way to broadcast the delegate by making sure there are binds first? Kind of like Unity's "DelegateFunc?.Invoke()"?
@vitaliikhomenia202
@vitaliikhomenia202 3 жыл бұрын
Thanks)
@ahmadalastal5303
@ahmadalastal5303 4 жыл бұрын
So Delegates and Event Dispatchers are the same ?
@TomHenryCoursow
@TomHenryCoursow 8 жыл бұрын
Hi what I have to to make this work in blueprint because of the "BlueprintAssignable"? I delcared a Dynamic Multicast Delegate in C++ and added it as property with blueprint assignable... Then I got a blueprint where I wanted to add this event dispatcher... I clicked on the "+" Button as I selected the Variable who contains the delegate declaration and it added a function to the wanted blueprint. But if I broadcast in C++... The event in the other class never gets called.... Isn't the delegate bound to the logic i implement in blueprint if I add it via + Button in Blueprint Editor??? I need help :(
@matthewhennegan839
@matthewhennegan839 8 жыл бұрын
+Tom - Henry Coursow Hi Tom, Is that instance of the class with the delegate broadcasting the event? ie. if you just create a variable of the class which can call the event, and add an event for it but you never set that variable to a real reference of something which is calling the broadcast, it will never fire. Can you give some more information about the set-up you've made?
@TomHenryCoursow
@TomHenryCoursow 8 жыл бұрын
Matthew Hennegan​ ok. So I have a C++ Actor Class "BattleManager" where beginplay reads Battle Setup Fighter Data from the GameInstance. Then the BattleManager spawns these fighters and calls: OnNewActiveFighter.Broadcast(spawnedFighter). Then I have a BattleHUD (HUD Class) Blueprint which adds my battle UI to the screen in beginplay and searches for a battle manager in the world and sets this to a variable. On this variable I clicked and added the OnNewActiveFighter Event via the + Button on the right bottom of the Details Panel. Then there was a Node in the BattleHUD Blueprint "OnNewActiveFighter (BattleManager)" where I placed my logic to add a ATB Icon for the specific Fighter but it never gets called... I also tried to move the spawn and broadcasting logic to Tick() within a if(!isInit) Block but also so it is not working so I don't think that it is a order problem of BeginPlay. The BattleManager variable is also not null
@il4w
@il4w Жыл бұрын
How do we do the unbind part in c++ ?
@niallmaple
@niallmaple 7 жыл бұрын
Nice video, helps with getting started with the more advanced side within c++ However, do you think you need to check if the delegate function is already bound within the overlap, so u arent overbinding it essentially ? Something like this gyazo.com/83fc0fad9a9c4ab778997d270c41041b
@matthewhennegan839
@matthewhennegan839 7 жыл бұрын
Seems like a good addition. For this video I was just trying to cover the basics of the syntax but yeah you'd want to ensure you're not binding the same object multiple times. Though it'd be worth digging through the source to check they're not already doing that check inside the AddDynamic macro somewhere, I haven't looked that far into it tbh.
@niallmaple
@niallmaple 7 жыл бұрын
Ah right, Unreal might be doing it already true
@sherifmedhat8625
@sherifmedhat8625 Жыл бұрын
why is this overly complicated than it should be.
Unreal Engine - Event Dispatchers Explained!
21:17
Reids Channel
Рет қаралды 19 М.
C++ Collision and Delegates UE4 / Unreal Engine 4 C++
13:49
Dev Enabled
Рет қаралды 28 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 91 МЛН
ROCK PAPER SCISSOR! (55 MLN SUBS!) feat @PANDAGIRLOFFICIAL #shorts
00:31
Василиса наняла личного массажиста 😂 #shorts
00:22
Денис Кукояка
Рет қаралды 9 МЛН
Unreal Engine Interfaces: Everything you need to know #2 C++ Implementation
14:43
07B Behavior Trees
24:16
Jonathan Burnside
Рет қаралды 13 М.
Lets Talk About Delegates
21:46
Rukgul
Рет қаралды 1,3 М.
UE4 Tutorial: Character Health Bar UI Using C++
22:01
_benui
Рет қаралды 14 М.
How to make C++ run FASTER (with std::async)
23:10
The Cherno
Рет қаралды 256 М.
Multiplayer in Unreal Engine: How to Understand Network Replication
22:08
UMG Widgets with C++ in Unreal Engine 5
16:09
Lively Geek
Рет қаралды 34 М.
Unreal Engine C++ Fundamentals - AHUD, UUserWidget & UWidgetAnimation
59:07
Jolly Monster Studio
Рет қаралды 23 М.
WHAT ARE "TIGHT" CONTROLS? - Movement in Games
9:14
JoshFTL
Рет қаралды 346 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 91 МЛН