Announcement

Collapse
No announcement yet.

C++ Event dispatchers: How do we implement them?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Click image for larger version

Name:	checkpoint.png
Views:	1
Size:	280.4 KB
ID:	1111436Click image for larger version

Name:	Tracker.png
Views:	1
Size:	375.1 KB
ID:	1111437

    Hi !
    I not sure if this is the right place to ask this question, so please guide me if it is not.

    Current I am doing the "Time Attack Racer" example, I wrote the 'checkpoint' entirely in C++ while the other actors in blueprint (Cause I need the checkpoint to do other things for my project).But I am Stuck at the Event dispatcher, I tried the above ' event dispatch' method in my checkpoint and cannot bind it to 'Tracker' in the blueprint.
    Any Help is appreciated !
    Thank

    cheer
    YanJie
    Last edited by yanjieng; 07-03-2016, 11:45 AM.

    Comment


      #17
      Originally posted by eXi View Post
      Code:
      #pragma once
      
      #include "GameFramework/PlayerController.h"
      #include "MyPlayerController.generated.h"
      
      /**
       * 
       */
      
      DECLARE_DYNAMIC_MULTICAST_DELEGATE(FTestDelegate);
      
      UCLASS()
      class SOCKETTEST_API AMyPlayerController : public APlayerController
      {
      	GENERATED_UCLASS_BODY()
      	
      	
      public:
      	virtual void Tick(float DeltaTime) override;
      	virtual void BeginPlay() override;
      
              void TestFunction();
      
      	UPROPERTY(BlueprintAssignable, Category = "Test")
      		FTestDelegate OnTestDelegate;
      };
      Hi, fairly new UE user here.
      I noticed making the delegate function private also works. Is there any reason for it to be public instead of private?

      Thanks!

      Comment


        #18
        Originally posted by bloodmeat10 View Post
        Hi, fairly new UE user here.
        I noticed making the delegate function private also works. Is there any reason for it to be public instead of private?

        Thanks!
        If it works with them being private, then no.
        Have you tested binding the Delegate in a different BP Class then "MyPlayerController"?
        Blueprint exposed UPROPERTY's always tell me they can't be private. So I thought protected and public is better here :x
        Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR | My Website

        My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
        (Including 100+ Pages Multiplayer Network Compendium to get you started.)

        BP Multiplayer Lobby System: [Released] Support Thread | BP Multiplayer Crafting System: [Released] Support Thread

        Comment


          #19
          Originally posted by eXi View Post
          If it works with them being private, then no.
          Have you tested binding the Delegate in a different BP Class then "MyPlayerController"?
          Blueprint exposed UPROPERTY's always tell me they can't be private. So I thought protected and public is better here :x
          You can add "meta = (AllowPrivateAccess = true)" to the UPROPERTY macro on a private field, which explicitly gives Blueprint permission to read and write that field. For dynamic multicast delegates I prefer to keep the field private, apply AllowPrivateAccess, and provide a public read-only accessor to the delegate for C++ code to bind to it. That way users of your code can't accidentally overwrite the delegate with a different instance.

          Comment


            #20
            Very useful post here. Having just implemented a C++-declared Event Dispatcher per the above - a note, for full functionality you will want to add BlueprintCallable as well to allow your blueprint to call your event dispatcher:

            > UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Test")
            > FTestDelegate OnTestDelegate;

            Comment


              #21
              Wiki on Blueprint Events / C++ Delegates

              Dear Community,

              I have a wiki on this topic here:

              How to create Blueprint Events from C++ & C++ Delegates
              https://wiki.unrealengine.com/Delega...and_BP_Exposed

              Excerpt:
              Level Blueprint Friendly Delegates

              When you've made BP-friendly delegates on objects that you can place in the level, you can simply right click on the object instance in your level -> Add Event and see your new delegate! So nice!

              This is an additional benefit of using DYNAMIC_MULTICAST delegates! Multi-cast implies binding multiple of various object instances to the delegate and then firing off the event to everyone from a single .Broadcast, which can include your Level Blueprint as a recipient/listener!



              Rama
              100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!

              UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

              Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama

              Comment

              Working...
              X