# Blueprintable delegates with return values

**URL:** <https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897>\
**Category:** Blueprint\
**Tags:** return, bind, unreal-engine, delegate, Blueprint, question\
**Created:** [March 28, 2015, 3:34am UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897 "2015-03-28T03:34:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsAcren](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/itsacren/32/1194653_2.png) [@itsAcren](https://forums.unrealengine.com/u/itsAcren)\
**Post date:** [March 28, 2015, 3:34am UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/1 "2015-03-28T03:34:09Z")

</div>

Is it possible to declare delegates with return values that can be assigned in Blueprint?

I know you can have input only events with BlueprintAssignable, but as far as I know the delegates have to be multicast and thus can’t return anything.

For some context: I have a base class of type Item. Items have different levels, and have different stats depending on the level. For example, item level 1 may give +10 damage, item level 2 may give +20 damage. The scaling is calculated in a function on the specific item subclass which takes the level as a parameter and outputs a float, like “float calculateDamageBonus(int32 itemLevel)” only it’s in Blueprint. The items have descriptions generated from the stats that they give. It’s pretty easy for an item to format a string to describe the stats it gives at a certain level. However I want to describe upgrading between these levels, eg. at level 1 the item says “Gives +10 damage” but when given the option to upgrade from level 1 to 2, I want to be able to generate “Gives +[10 → 20] damage” so that the player can see which stats are being upgraded by how much.

I want Item subclasses to be able to call a helper function somewhere that takes a delegate (which refers to the stat calculator function on the item that takes an integer param and returns a float) as a parameter, and returns a string.  
The helper function calls the delegate multiple times with different integers for different levels, and formats the resulting float values into a string such as “[10 → 20]” and returns that.

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [July 11, 2015, 6:21pm UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/2 "2015-07-11T18:21:57Z")

</div>

Bump. Did you discover anything? I’m guessing it’s not possible, but that seems like a rather large and unexpected limitation. Or is there a workaround that I’m not seeing?

---

<div class="post-metadata">

**Author:** ![itsAcren](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/itsacren/32/1194653_2.png) [@itsAcren](https://forums.unrealengine.com/u/itsAcren)\
**Post date:** [July 12, 2015, 5:49am UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/3 "2015-07-12T05:49:31Z")

</div>

Nope, haven’t found or heard anything about this unfortunately.

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [July 12, 2015, 8:46pm UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/4 "2015-07-12T20:46:59Z")

</div>

Yep, that’s a pity. Would be nice to know if there are any plans to add this functionality to Blueprints. Thanks for updating, anyway.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8ab98422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8ab98422](https://forums.unrealengine.com/u/anonymous_user_8ab98422)\
**Post date:** [July 12, 2015, 9:49pm UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/5 "2015-07-12T21:49:28Z")

</div>

Have you tried something like this:

```
DECLARE_DELEGATE_RetVal_OneParam(int32, FMyEventDelegate, bool);

/* The UPROPERTY is experimental and not tested */
UPROPERTY(BlueprintAssignable)
FMyEventDelegate OnMyEvent;

int32 GetMyEventResult(bool EventConditional) const
{
	if(OnMyEvent.IsBound())
	{
		return OnMyEvent.Execute(EventConditional);
	}

	return 0;
}

```

Take a look at Engine\Source\Runtime\Core\Public\Delegates\DelegateCombinations\_Variadics.h

There is pretty much every possible delegate type you might ever need.

If that does not give you a blueprintable Delegate, you can still declare GetMyEventResult() as UFUNCTION that is BlueprintCallable

Edit: Just realized you wanted a blueprintable Delegate.

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [July 12, 2015, 9:54pm UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/6 "2015-07-12T21:54:51Z")

</div>

Thanks, but the issue is working with such a delegate in Blueprint, not C++. Only dynamic delegates can be exposed to Blueprint. Further, even though non-multicast dynamic delegates can be exposed, there is no obvious way to assign a function to one in BP when the delegate has a return value.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8ab98422](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8ab98422](https://forums.unrealengine.com/u/anonymous_user_8ab98422)\
**Post date:** [July 12, 2015, 10:03pm UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/7 "2015-07-12T22:03:30Z")

</div>

Ah if that is what you want, why not use an Interface with BlueprintImplementableEvent?

> **[Return a value from a BlueprintImplementableEvent](https://forums.unrealengine.com/questions/57955/return-a-value-from-a-blueprintimplementableevent.html)**
>
> I wish to write a function whose implementation is in Blueprint. Further, I would like this function to return a boolean value. I tried to create a BlueprintImplementableEvent that returned a boolean. However, despite no errors from UBT, this did not...

The Reference& parameters will be converted to return values.

---

<div class="post-metadata">

**Author:** ![itsAcren](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/itsacren/32/1194653_2.png) [@itsAcren](https://forums.unrealengine.com/u/itsAcren)\
**Post date:** [August 18, 2015, 4:04am UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/8 "2015-08-18T04:04:27Z")

</div>

How can I pass the function by delegate to another function which can call it? Added to description for context.

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [August 18, 2015, 9:17pm UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/9 "2015-08-18T21:17:17Z")

</div>

I still don’t believe it is possible to use delegates like this in BP unfortunately, but from what you describe it doesn’t sound to me like you need delegates in this case.

You could make `CalculateDamageBonus` a BlueprintImplementableEvent. Then your BP item subclasses would implement the override rather than declaring a new function. You can then have a function in your item base class such as `FormatUpgrade(int32 FromLevel, int32 ToLevel)` which just calls `CalculateDamageBonus` for each level and does the formatting. Wouldn’t that achieve what you want?

---

<div class="post-metadata">

**Author:** ![itsAcren](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/itsacren/32/1194653_2.png) [@itsAcren](https://forums.unrealengine.com/u/itsAcren)\
**Post date:** [October 5, 2015, 6:37am UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/10 "2015-10-05T06:37:52Z")

</div>

Following up on this, using an output parameter worked.

I use c++ to declare the delegate and a static formatting function which takes the delegate.

```
DECLARE_DYNAMIC_DELEGATE_TwoParams(FItemCalculatorDelegate, uint8, stack, float&, output);

// Uses the given item value calculator function to format scaling values for a description
UFUNCTION(BlueprintPure, Category = "Item")
static FText formatScalingValue(FItemCalculatorDelegate valueCalculator, uint8 stack = 1, uint8 upgradeCount = 0, float multiplier = 100, int32 maxFractionalDigits = 1);

```

In BP I define a function with the same signature as the delegate:

[http://i.imgur.com/PYPk2HF.png](http://i.imgur.com/PYPk2HF.png)

Then elsewhere in BP I can specify that function using the Create Event node and pass it as a parameter into the formatting function defined in C++.

[http://i.imgur.com/nmqtbgv.png](http://i.imgur.com/nmqtbgv.png)

---

<div class="post-metadata">

**Author:** ![disaster0203](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@disaster0203](https://forums.unrealengine.com/u/disaster0203)\
**Post date:** [July 28, 2019, 11:02pm UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/11 "2019-07-28T23:02:27Z")

</div>

Acren you saved my life!

I know this is pretty late but it seems like this problem still exists. In my answer, I would like to show a more concrete version of Acrens comment where you can also pass blueprint functions via lambda to external libraries.

I have a color library where you can store custom gamma functions inside std::functions. My goal was to store Blueprint functions there as well:

Declare the delegate:

```
DECLARE_DYNAMIC_DELEGATE_TwoParams(FGammaFunctionDelegate, float, InputValue, float&, OutputValue);

```

Save the delegate in a variable inside a UCLASS:

```
FGammaFunctionDelegate gamma_delegate;

```

Define a BlueprintCallable function that takes the delegate as a parameter:

```
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Create Gamma Function"))
		static UGammaFunctionPart* CreateGammaFunctionPart(FGammaFunctionDelegate Function, float UpperBorder);

```

Inside this function create a lambda which executes the delegate (and pass the lambda to a object of the external library):

```
gamma_delegate = Function;
gamma_function = new color_space::gamma_part([this](float Input)
{
	float result;
	gamma_delegate.ExecuteIfBound(Input, result);
	return result;
}, UpperBorder);

```

Now unreal somehow knows that the return value of a blueprint function has to be assigned to the reference parameter…

A sample gamma blueprint function might look like this:

 ![283468-gammafunction.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/d/04d68baa12e7d78acd6bf59439fdc6fc1024c44d.png)

And this way you can assign the blueprint function:

![283470-createevent.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/0/a100ed5d4075a9fe00af9b8923e322905d4b86b4.png)

Now each time the external library tries to do a gamma correction it will execute the std::function which stores a lambda. The lambda will call the delegate which finally executes the blueprint function. The return value will be passed down to the point where the std::function was called.

---

<div class="post-metadata">

**Author:** ![simulacrumgames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simulacrumgames/32/482168_2.png) [@simulacrumgames](https://forums.unrealengine.com/u/simulacrumgames)\
**Post date:** [November 13, 2024, 2:47pm UTC](https://forums.unrealengine.com/t/blueprintable-delegates-with-return-values/312897/12 "2024-11-13T14:47:18Z")

</div>

For future reference you can replace most of your solution with this (at least you can in UE5.4):

```auto
UPROPERTY(BlueprintReadWrite)
FGammaFunctionDelegate gamma_delegate;

```
