Nice way to bind delegates to functions in editor?

Anyone know if there’s a UPROPERTY type that can allow binding a delegate to a function of an object in the editor? I was just thinking it’d be nice to be able to allow users to bind my plugin’s multicast delegates to their own function implementations, but don’t recall seeing such a beast so far.

You can use the property specifier to the meta tags.


UPROPERTY(BlueprintAssignable)
      DelegateType VariableName;

```](https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Properties/Specifiers/BlueprintAssignable/)
From there you can bind it to any function in the BP graph.

Hope it helps.

Doesn’t that just make it so you can assign a blueprint function call to it?

I guess that wouldn’t be so bad, but I’d rather assign it to C++ functions as well.

Maybe i misunderstod you.
What the above dose is expose the Delegate Member in the class to blueprints.
That way you can grab it in BP and do what you want e.g: Bind function on Broadcast.

If you wanted to flip it and Broadcast the delegate “event” from a new function you can do that as well with the same member…

Also not 100% sure what you’re asking for, but BlueprintAssignable will let you bind any compatible function, whether it’s defined in Blueprint or C++. If C++, it needs to be marked UFUNCTION(BlueprintCallable).

This is for runtime binding from a Blueprint graph though. There’s currently no way to have a dropdown box in the details panel where you can statically bind an arbitrary delegate on an actor/component to a C++ function on the actor. It would be nice if there was.

The only thing you can do is something like this (untested)


//.h

DECLARE_DELEGATE(FTheDelegate);
DECLARE_DYNAMIC_DELEGATE(FTheDynamicDelegate);

virtual void PostEditPropertyChanged(/*param*/) override;

UPROPERTY(Category = "Delegate", EditAnywhere)
FName DelegateUFunctionName;

UPROPERTY(Category = "Delegate", EditAnywhere)
UObject* DelegateUObject;

UPROPERTY(BlueprintReadWrite, Category = "Delegate", VisibleAnywhere)
FTheDelegate Delegate;

UPROPERTY(BlueprintReadWrite, Category = "Delegate", VisibleAnywhere)
FTheDynamicDelegate DynamicDelegate;


//.cpp

void TheClass::PostEditPropertyChanged(param)
{
	Super::PostEditPropertyChanged(param);

	if (/*DelegateUFunctionName OR DelegateUObject property was changed*/)
	{
		//for regular delegates
		Delegate.BindUFunction(DelegateUObject, DelegateUFunctionName);

		//for dynamic delegates
		DynamicDelegate.BindUFunction(DelegateUObject, DelegateUFunctionName);
	}
}


2 Likes

You have saved me from throwing my pc off the balcony, thank you! Wanted to be able to assign functions that I need some other delegates to run in the editor, modified your example a bit and it works like magic now.