Download

Invoking a delegate function from Blueprints

Is there a way to invoke a delegate from blueprint if it is passed as a parameter to a function?

I didn’t figure out a way in BP but in C++.

Pastebin: Unreal Reactive Event - Pastebin.com


 

  1. #pragma once
  1. #include "CoreMinimal.h"
  1. #include "UObject/NoExportTypes.h"
  1. #include "ReactiveEvent.generated.h"
  1. DECLARE_DYNAMIC_DELEGATE(FReactiveEventDelegate);
  1. DECLARE_DYNAMIC_MULTICAST_DELEGATE(FReactiveEventDelegateMulti);
  1. UCLASS(Blueprintable, BlueprintType)
  1. class GRILLMASTER_API UReactiveEvent : public UObject
  1. {
  1. GENERATED_BODY()
  1. public:
  1. FReactiveEventDelegateMulti OnEventInvoked;
  1. bool bWasCalled;
  1. UFUNCTION(BlueprintCallable)
  1. void Subscribe(const FReactiveEventDelegate& callback)
  1. {
  1. OnEventInvoked.Add(callback);
  1. if(bWasCalled)
  1. {
  1. callback.Execute();
  1. }
  1. }
  1. UFUNCTION(BlueprintCallable)
  1. void OnNext()
  1. {
  1. bWasCalled = true;
  1. OnEventInvoked.Broadcast();
  1. }
  1. };

 

In BP, the CreateEvent Node might do it.
But how did you pass in the red wire???
Or is this just a mockup illustration etc?

CreateEvent Node creates a delegate that can be invoked late on. So that would be what I would pass into the function.
I looked over all the calls that are shown in the context menu for a delegate (there aren’t many) and nothing resembles anything that might invoke the delegate.

You can take any Bind Event to XYZ node and drag a connection from the red dot to the function parameter area. This creates a genetic delegate input parameter.