# How can I call a Blueprint function inside C++ code?

**URL:** <https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462>\
**Category:** Blueprint\
**Tags:** calling-a-function, unreal-engine, CPP, Blueprint, question\
**Created:** [November 20, 2014, 12:31pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462 "2014-11-20T12:31:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![yurembo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@yurembo](https://forums.unrealengine.com/u/yurembo)\
**Post date:** [November 20, 2014, 12:31pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/1 "2014-11-20T12:31:24Z")

</div>

How could I call a Blueprint function from a C++ code?  
After an event in C++ cod I need to call a Blueprint function to show a dialog. I know I should use a BP “add to viewport” function, but how to call this from C++?  
Any answers will be great!  
Thank you!

---

<div class="post-metadata">

**Author:** ![BaderThanBad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BaderThanBad](https://forums.unrealengine.com/u/BaderThanBad)\
**Post date:** [November 20, 2014, 12:44pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/2 "2014-11-20T12:44:59Z")

</div>

To call a blueprint function from c++ you need to get a UBlueprint pointer in the constructor of the class you want to call from then later call the FindFunction on that which will return a UFunction pointer. You will have to manualy set the properties then ProcessEvent with the UFunction. There should be some examples online if you look for them.

---

<div class="post-metadata">

**Author:** ![yurembo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@yurembo](https://forums.unrealengine.com/u/yurembo)\
**Post date:** [November 20, 2014, 2:07pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/3 "2014-11-20T14:07:19Z")

</div>

Where can I find examples?

---

<div class="post-metadata">

**Author:** ![yurembo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@yurembo](https://forums.unrealengine.com/u/yurembo)\
**Post date:** [November 20, 2014, 2:16pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/4 "2014-11-20T14:16:33Z")

</div>

Can you point me to the right manual of this subject? Thanks!

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [November 20, 2014, 2:18pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/5 "2014-11-20T14:18:20Z")

</div>

Here is an example from the First Person Shooter C++ Tutorial from epic:

```
static ConstructorHelpers::FObjectFinder<UBlueprint> PlayerPawnObject(TEXT("Blueprint'/Game/Blueprints/BP_FPSCharacter.BP_FPSCharacter'"));
   if (PlayerPawnObject.Object != NULL)
   {
       DefaultPawnClass = (UClass*)PlayerPawnObject.Object->GeneratedClass;
   }

```

The ContructorHelpers::FObjectFinder is helpfull to find Blueprints. In this example it finds the

```
TEXT("Blueprint'/Game/Blueprints/BP_FPSCharacter.BP_FPSCharacter'")

```

So you need the exact folder structure and BP Name. After that, the if checks if the UObject is not NULL and saves it’s Class by Casting the GeneratedClass to a basic UClass. I guess that could help you :X

---

<div class="post-metadata">

**Author:** ![BaderThanBad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BaderThanBad](https://forums.unrealengine.com/u/BaderThanBad)\
**Post date:** [November 20, 2014, 2:35pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/6 "2014-11-20T14:35:19Z")

</div>

With that pointer you can cache the result of FindFunction then call ProcessEvent on the blueprint pointer with your cached UFunction\*. nullptr for no properties, or set whichever properties your blueprint node needs.

With that said, the recommended approach is really to do it the other way around. [link text](https://answers.unrealengine.com/questions/116529/call-blueprint-functions-from-c.html)

---

<div class="post-metadata">

**Author:** ![BaderThanBad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BaderThanBad](https://forums.unrealengine.com/u/BaderThanBad)\
**Post date:** [November 20, 2014, 2:36pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/7 "2014-11-20T14:36:47Z")

</div>

I think the C++ tutorial on youtube by epic does something like this so check it out.

---

<div class="post-metadata">

**Author:** ![yurembo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@yurembo](https://forums.unrealengine.com/u/yurembo)\
**Post date:** [November 20, 2014, 2:39pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/8 "2014-11-20T14:39:00Z")

</div>

I’m using a Puzzle Template and here DefaultPawnClass is NULL

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [November 20, 2014, 2:46pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/9 "2014-11-20T14:46:54Z")

</div>

It is just an example. You can use this to find any available Blueprint. This here is searching for the “BP\_FPSCharacter”. You just need to change this to the BP you want to have a pointer to.

---

<div class="post-metadata">

**Author:** ![yurembo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@yurembo](https://forums.unrealengine.com/u/yurembo)\
**Post date:** [November 20, 2014, 4:59pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/10 "2014-11-20T16:59:11Z")

</div>

This Class hasn’t a visual asset, therefore it doesn’t load anything like:  
TEXT(“Blueprint’/Game/Blueprints/BP\_FPSCharacter.BP\_FPSCharacter’”)

---

<div class="post-metadata">

**Author:** ![yurembo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@yurembo](https://forums.unrealengine.com/u/yurembo)\
**Post date:** [November 20, 2014, 5:33pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/11 "2014-11-20T17:33:20Z")

</div>

I made :  
UFunction \*func = FindFunction(TEXT(“ShowWin”));  
ProcessEvent(func, nullptr);

but it’s not work

---

<div class="post-metadata">

**Author:** ![RemRemRemRe](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/remremremre/32/974428_2.png) [@RemRemRemRe](https://forums.unrealengine.com/u/RemRemRemRe)\
**Post date:** [December 28, 2024, 7:10pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-blueprint-function-inside-c-code/299462/12 "2024-12-28T19:10:06Z")

</div>

> [@A sample for calling a UFunction with reflection?](https://forums.unrealengine.com/t/a-sample-for-calling-a-ufunction-with-reflection/276416/15):
>
> I made one of these things recently and with editor support, check the code bellow for more information: RemReflectedFunctionCallData which support calling a static or memberUFUNCTION, with almost any parameters(except parameter of delegate type (or more) for now because of limitation of FInstancedPropertyBag), and has return value. I’m searching for populating default value for these parameters ATM.
