# How to pass a function as parameter of UFUNCTION() function?

**URL:** <https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332>\
**Category:** C++\
**Tags:** unreal-engine, functions, CPP, question\
**Created:** [February 14, 2018, 5:37pm UTC](https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332 "2018-02-14T17:37:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_210522a1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_210522a1](https://forums.unrealengine.com/u/anonymous_user_210522a1)\
**Post date:** [February 14, 2018, 5:37pm UTC](https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332/1 "2018-02-14T17:37:10Z")

</div>

Hello there!

So I am trying to pass a function to another function, similair to the FTimerManager.SetTimer.

I just can’t get it to work. I have looked a little into TFunction and TFunctionRef, but I couldn’t find good enough sources for me. Lamdba’s could be another way to go I heard, but I also have heard of function pointers.  
Where do I start? And where are good sources/examples.

I am fine with only taking void functions with no parameters. As for why I am trying to do this, I am trying to expose some of the multithreading capabilities to blueprints.

Thanks in advance

-

---

<div class="post-metadata">

**Author:** ![Balgy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Balgy](https://forums.unrealengine.com/u/Balgy)\
**Post date:** [February 14, 2018, 7:32pm UTC](https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332/2 "2018-02-14T19:32:32Z")

</div>

TFunction is what you need. Anything else is just more work and unneeded complication for me.

Declare a function then add TFunction as a parameter.

```
void MyFunction( TFunction<void(int32 Numparam)> MyFunctionToCall)

```

TFunction works like std::function in normal C++ therefore, “void” is the function’s return type and anything inside the ( ) is the parameters, which can be left empty.

TFunction can’t be a parameter in a UFUNCTION() so keep that in mind.

A simpler way to use function pointers is with a typedef. There is a great tutorial which I link below:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_210522a1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_210522a1](https://forums.unrealengine.com/u/anonymous_user_210522a1)\
**Post date:** [February 14, 2018, 10:01pm UTC](https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332/3 "2018-02-14T22:01:18Z")

</div>

Thank for your answer, seems good for c++, but I need it to be UFUNCTION() for blueprints. How would I go around that?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_210522a1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_210522a1](https://forums.unrealengine.com/u/anonymous_user_210522a1)\
**Post date:** [February 14, 2018, 10:35pm UTC](https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332/4 "2018-02-14T22:35:33Z")

</div>

I now have it working with a delegate, it should work, but it would be nicer if I can pass a function name or something from the BP.

For people looking at this later this is how the delegate works:  
C++:  
DECLARE\_DYNAMIC\_DELEGATE(FunctionDelegate);

```
UCLASS(...)
.....

UFUNCTION(...)
void CreateThread(FunctionDelegate functor) { functor.ExecuteIfBound(); }

```

BP:

 ![230716-delegate.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/8/e/48e062ef5a007ec3d9ebf1c14c211f987b42670f.png)

---

<div class="post-metadata">

**Author:** ![Balgy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Balgy](https://forums.unrealengine.com/u/Balgy)\
**Post date:** [February 14, 2018, 11:23pm UTC](https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332/5 "2018-02-14T23:23:45Z")

</div>

You could add a 2nd function which will be a UFUNCTION() and pass it the return value of your TFunction and use that 2nd function to expose the value in BP. Other than that, yes delegates are a bit more complex but it is the way unreal adds function calls on runtime.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_63c6b7a8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_63c6b7a8](https://forums.unrealengine.com/u/anonymous_user_63c6b7a8)\
**Post date:** [August 29, 2019, 2:27pm UTC](https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332/6 "2019-08-29T14:27:46Z")

</div>

You may need to pass the parameter as a reference.  
Didn’t work for me without it.

Example:

```
UFUNCTION(...)
void CreateThread(FunctionDelegate& functor) { functor.ExecuteIfBound(); }

```

---

<div class="post-metadata">

**Author:** ![Kevin\_RedPillVR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kevin_redpillvr/32/88715_2.png) [@Kevin\_RedPillVR](https://forums.unrealengine.com/u/Kevin_RedPillVR)\
**Post date:** [November 3, 2021, 12:02am UTC](https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332/7 "2021-11-03T00:02:23Z")

</div>

What UFUNCTION specifiers did you use to make it available in blueprint? I tried blueprint callable but that didn’t seem to work.

---

<div class="post-metadata">

**Author:** ![Kevin\_RedPillVR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kevin_redpillvr/32/88715_2.png) [@Kevin\_RedPillVR](https://forums.unrealengine.com/u/Kevin_RedPillVR)\
**Post date:** [November 3, 2021, 12:14am UTC](https://forums.unrealengine.com/t/how-to-pass-a-function-as-parameter-of-ufunction-function/417332/8 "2021-11-03T00:14:00Z")

</div>

What UFUNCTION specifiers did you use to make it available in blueprint? I tried blueprint callable but that didn’t seem to work.
