# Call A BluePrint function from C++

**URL:** <https://forums.unrealengine.com/t/call-a-blueprint-function-from-c/322839>\
**Category:** Blueprint\
**Tags:** calling-a-function, unreal-engine, UE4, CPP, Blueprint, question\
**Created:** [June 24, 2015, 5:52am UTC](https://forums.unrealengine.com/t/call-a-blueprint-function-from-c/322839 "2015-06-24T05:52:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_8b0af009](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8b0af009](https://forums.unrealengine.com/u/anonymous_user_8b0af009)\
**Post date:** [June 24, 2015, 5:52am UTC](https://forums.unrealengine.com/t/call-a-blueprint-function-from-c/322839/1 "2015-06-24T05:52:43Z")

</div>

I am using C++ and I have a BluePrint function library callled MyFunction which displays a message to the output log.

How can I call this function from C++?

I am at a complete loss here 😕

---

<div class="post-metadata">

**Author:** ![eagletree](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eagletree](https://forums.unrealengine.com/u/eagletree)\
**Post date:** [June 24, 2015, 2:50pm UTC](https://forums.unrealengine.com/t/call-a-blueprint-function-from-c/322839/2 "2015-06-24T14:50:09Z")

</div>

One way would be to create an BlueprintableEvent allowing a blueprint to be triggered and call the function.

> **[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...

I didn’t have success when I tried this, due to using a Mac and how XCode has to be started in a certain manner to make it work (I wasn’t aware of that at the time I attempted the event generation) but I think it’s the correct way to do it. Instead I ended up using communication via variables between blueprints and C++. For example, creating a bool visible to the extended blueprint that is interrogated in the blueprint and thus lets you do anything a blueprint can do (in your case, make the function call). Either way, your extended blueprint from your C++ class should be able to be informed to call the library functions. I can’t help concerning the library call, because I don’t use any blueprint libraries.

Using my method, if the function to be called requires a variable to be passed from C++, you will have to also make that variable visible to the C++ Class’s blueprint, then pass it to the library function. Using the event method (the better approach), note how Rama shows passing the value of variable “CurrentHealth” in the linked example. If CurrentHealth were needed to then pass to the library function, it would be available for that purpose.

While these are useful techniques, hopefully someone else will answer if there is a way to directly call the blueprint library function. I’m not aware of any.

Note, if you use a Mac, to do any of this requires starting the editor from XCode or C++ so variables and events will be seen in the blueprint. This is because the hot reload doesn’t make the blueprint aware of new variables or events unless previously built in XCode prior to starting the Editor. I don’t know the details on windows, but I presume it probably “just works”. I just mention this because I wasted weeks trying to get blueprint\<-\>C++ communication working due to this still unresolved bug.

---

<div class="post-metadata">

**Author:** ![theonecalledtom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theonecalledtom](https://forums.unrealengine.com/u/theonecalledtom)\
**Post date:** [June 24, 2015, 3:47pm UTC](https://forums.unrealengine.com/t/call-a-blueprint-function-from-c/322839/3 "2015-06-24T15:47:19Z")

</div>

On Windows it Just Works ™

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_01dd28a6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_01dd28a6](https://forums.unrealengine.com/u/anonymous_user_01dd28a6)\
**Post date:** [June 25, 2015, 1:36am UTC](https://forums.unrealengine.com/t/call-a-blueprint-function-from-c/322839/4 "2015-06-25T01:36:55Z")

</div>

> **[Call Blueprint functions from C++](https://forums.unrealengine.com/questions/116529/call-blueprint-functions-from-c.html)**
>
> Hello, How can i call a Blueprint function from C++. So i have a buttonPressed() function that i call in c++ and now i want to do something when the buttonPressed() function was called in my Blueprint. thanks for any answers PS.: If anyone...

---

<div class="post-metadata">

**Author:** ![smilingrob](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/smilingrob/32/947302_2.png) [@smilingrob](https://forums.unrealengine.com/u/smilingrob)\
**Post date:** [November 18, 2015, 6:06am UTC](https://forums.unrealengine.com/t/call-a-blueprint-function-from-c/322839/5 "2015-11-18T06:06:22Z")

</div>

If you had a blueprint function called `SetBlockNumber` and it takes an integer.  
Then in C++ you can use the UObject::**[CallFunctionByNameWithArguments](https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/UObject/CallFunctionByNameWithArguments/index.html)** function to call it like this.

```
const FString command = FString::Printf(TEXT("SetBlockNumber %d"), block.BlockId);
FOutputDeviceDebug debug;
blockActor->CallFunctionByNameWithArguments(*command, debug, this, true);

```
