UE4 c++ Event Dispatchers syntax

Sdílet
Vložit
  • čas přidán 19. 02. 2016
  • 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.

Komentáře • 40

  • @ReaverPS
    @ReaverPS Před 8 lety +16

    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  Před 8 lety

      +ReaverPS Thanks!

    • @pratyushbsingh5995
      @pratyushbsingh5995 Před 7 lety

      ReaverPS yea theyve made delagates in the docs pretty dense

    • @Khross30
      @Khross30 Před 6 lety

      Seriously, I tried to understand their docs but eventually my eyes just glazed over...

  • @m0rph3u5.
    @m0rph3u5. Před rokem +1

    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 Před 4 lety +2

    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 Před 3 lety

      For direct parent to child communication it might be better to use references instead.

  • @elsnowman123
    @elsnowman123 Před 2 lety +1

    Incredible video. Straight to the point. Thanks!

  • @rfw77591
    @rfw77591 Před 7 lety +1

    thanks a lot Matt, very useful tutorial, straight and to the point!

  • @Jonathanlambert-art
    @Jonathanlambert-art Před 7 lety +2

    It's short, concise, and easy to understand. Thank you!

  • @codezeeroify
    @codezeeroify Před 7 lety

    a very simple and a clear explanation, wish upload more vids . thanks !

  • @arjunjain7773
    @arjunjain7773 Před 3 lety

    Very useful and I understand Dispatchers a lot better now

  • @dmdmdm_
    @dmdmdm_ Před 8 lety

    Thanks a lot for your tutorials. They help a lot with getting my c++ project going.

    • @matthewhennegan839
      @matthewhennegan839  Před 8 lety

      No worries, thanks for taking the time to comment, much appreciated.

  • @inakidiez5428
    @inakidiez5428 Před 2 lety

    I know this isnt updated but it still helped me a lot. Thanks

  • @thephysicist989
    @thephysicist989 Před 2 lety

    Thank you so much for this video! Theres very few videos out there with advanced c++ topics in Unreal Engine

  • @jellyfith
    @jellyfith Před 5 lety

    Awesome explanation thank you

  • @soumikbhattacherjee6430

    Thank you verymuch. Its worked on 4.22

  • @pirofagista
    @pirofagista Před 7 lety

    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.

  • @digitalmessiah7325
    @digitalmessiah7325 Před 3 lety

    Still relevant. thx ;)

  • @GiraffePi
    @GiraffePi Před 7 lety

    quick and awesome!

  • @GeNN18192
    @GeNN18192 Před 2 lety

    Thank you in 2022, still not much resources around for UE C++ event system!

  • @ryanfrank4299
    @ryanfrank4299 Před 7 lety

    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  Před 7 lety

      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.

  • @vitaliikhomenia202
    @vitaliikhomenia202 Před 3 lety

    Thanks)

  • @prezadent1
    @prezadent1 Před 6 lety +23

    Please make the code a little smaller, I can still make out some parts of it.

  • @edbeable2659
    @edbeable2659 Před 3 lety

    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 Před 8 měsíci

    Is there a safe way to broadcast the delegate by making sure there are binds first? Kind of like Unity's "DelegateFunc?.Invoke()"?

  • @TomHenryCoursow
    @TomHenryCoursow Před 8 lety

    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  Před 8 lety

      +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 Před 8 lety

      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

  • @ahmadalastal5303
    @ahmadalastal5303 Před 4 lety

    So Delegates and Event Dispatchers are the same ?

  • @il4w
    @il4w Před rokem

    How do we do the unbind part in c++ ?

  • @niallmaple
    @niallmaple Před 7 lety +1

    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  Před 7 lety

      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 Před 7 lety

      Ah right, Unreal might be doing it already true

  • @sherifmedhat8625
    @sherifmedhat8625 Před rokem

    why is this overly complicated than it should be.