# Call Blueprint functions from C++

**URL:** <https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 14, 2014, 6:20pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119 "2014-10-14T18:20:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7161b5ff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7161b5ff](https://forums.unrealengine.com/u/anonymous_user_7161b5ff)\
**Post date:** [October 14, 2014, 6:20pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/1 "2014-10-14T18:20:19Z")

</div>

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 knows how i can play matinee in C++ it would be also helpful

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [October 14, 2014, 6:52pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/2 "2014-10-14T18:52:41Z")

</div>

Hey theJulman-

I’m a little unclear on your question. Is the buttonPressed() function created in the blueprint or in c++? It may be be easier to create the function in code with default functionality, then use blueprints for extended functionality as needed

Cheers

---

<div class="post-metadata">

**Author:** ![ScottSpadea](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/scottspadea/32/1194682_2.png) [@ScottSpadea](https://forums.unrealengine.com/u/ScottSpadea)\
**Post date:** [October 15, 2014, 4:53am UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/3 "2014-10-15T04:53:23Z")

</div>

//if you want to define a function in CPP that can be redefined or called in blueprint, do this:

//for a function named XXX inheriting from a class named YYY, you would write:

//inside the YYY.h class:

```
 UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ZZZ")
 void XXX();

```

//at the end of the YYY.CPP file:

```
 void YYY::XXX_Implementation()
 {
   //add code here
   AAA.doStuff();
 } 

```

//the “\_Implementation” suffix for the function name is only needed if you use “BlueprintNativeEvent”, and if you want to call that function from CPP, you just call " XXX(); " and not " XXX\_Implementation(); "

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7161b5ff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7161b5ff](https://forums.unrealengine.com/u/anonymous_user_7161b5ff)\
**Post date:** [October 15, 2014, 10:43am UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/4 "2014-10-15T10:43:04Z")

</div>

So thats how my PlayerCharacter.cpp looks like:

```
if(HitActor){
    AmyButton* myButton = Cast<class AmyButton>(HitActor);
    if(myButton){
       if(HitActor->ActorHasTag(FName("Play"))){
          myButton->buttonPlay();
       }
       else if(HitActor->ActorHasTag(FName("Reverse"))){
          myButton->buttonReverse
       }
    }
}

```

And myButton.h:

```
UFUNCTION(BlueprintCallable, Category = Buttonfunc)
void buttonPlay();

UFUNCTION(BlueprintCallable, Category = Buttonfunc);
void buttonReverse();

```

The Problem is I don’t know what i should use instead of BlueprintCallable

And here is my LevelBlueprint:

 ![17948-blueprint.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/0/c/80c3b9e0fe93e2cfb6f746dccfc2907c988a158e.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7161b5ff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7161b5ff](https://forums.unrealengine.com/u/anonymous_user_7161b5ff)\
**Post date:** [October 15, 2014, 11:50am UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/5 "2014-10-15T11:50:28Z")

</div>

Oke thanks this answer worked for me 🙂

---

<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, 9:45am UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/6 "2014-11-20T09:45:00Z")

</div>

How do you make this?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44fb6e0c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44fb6e0c](https://forums.unrealengine.com/u/anonymous_user_44fb6e0c)\
**Post date:** [March 16, 2015, 2:41pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/7 "2015-03-16T14:41:21Z")

</div>

I ahve no idea where you can plug this in the blueprints, I wasn’t able to find the new UFUNCTION anywhere

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [March 16, 2015, 6:12pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/8 "2015-03-16T18:12:19Z")

</div>

Adding UFUNCTION(BlueprintCallable) to the function declaration will expose the function to blueprints. Once you add it to the code and compile again you can open up a blueprint with access to the class and type the name of the function into the right-click search menu. Additionally adding “Category = ABC” after BlueprintCallable will allow you to search for the ABC category and anything (function or variable) with the same category will appear.

---

<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 6, 2015, 7:35pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/9 "2015-06-06T19:35:13Z")

</div>

Ok, got this working so here is an example…

I want to call a blueprint function from C++.

So first I make a blueprint function called CallFunctionTest.  
(In our game, and we call a player a “Survivor”.)  
It just prints “Survivor Call Function Test” in pink on the console.

Then I have a static blueprint set of functions like this…

The header file is

```
#include "Kismet/BlueprintFunctionLibrary.h"

#include "TDLSurvivorFastCache.generated.h"

/**
 * 
 */
UCLASS()
class TDL_API UTDLSurvivorFastCache : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()

public:

	UFUNCTION(BlueprintCallable, Category = TDLSurvivorCache)
		static void TestCPPCallToBP(AActor * c);
	
};

```

and the cpp file is…

```
#include "tdl.h"
#include "ConsoleManager.h"

#include "TDLSurvivorFastCache.h"
   
UTDLSurvivorFastCache::UTDLSurvivorFastCache(const class FObjectInitializer & PCIP)
	: Super(PCIP)
{
	UE_LOG(TDLLog, Log, TEXT("UTDLSurvivorFastCache"));
}

void UTDLSurvivorFastCache::TestCPPCallToBP(AActor * c)
{
	FOutputDeviceNull ar;
	c->CallFunctionByNameWithArguments(TEXT("CallFunctionTest"), ar, NULL, true);
}

```

Then we call the test function from our SurvivorBP blueprint and it calls the function on the SurvivorBP.

* * *

Here are the blueprints

![45483-testfunctionimpl.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/7/c/97c4966955b397ae14c83d5cef54194b560550b3.png)

![45484-calltotestcppfunc.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/e/4/3e45e8c23c505c8f8f04c9072ee1c00c19043dcd.png)

---

<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 6, 2015, 8:09pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/10 "2015-06-06T20:09:46Z")

</div>

Addendum:  
If you want to pass parmeters you just have to treat it as a command entry string.

So if i add an integer paramter to the Call Function Test then this works…

```
c->CallFunctionByNameWithArguments(TEXT("CallFunctionTest 42"), ar, NULL, true);

```

 ![45497-testfuncwithparam.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/e/f/eef5bc79262de6fc0f398461556d60dad313bdfa.png)

---

<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 6, 2015, 8:26pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/11 "2015-06-06T20:26:50Z")

</div>

Another bit of useful code…

```
char funcCallBuf[1024];

void UTDLSurvivorFastCache::CallActorFunc(AActor * c, FString funcName)
{
	FOutputDeviceNull ar;
	c->CallFunctionByNameWithArguments(*funcName, ar, NULL, true);
}

void UTDLSurvivorFastCache::CallActorFuncIntParam(AActor * c, FString funcName, int32 f)
{
	_snprintf(funcCallBuf, sizeof(funcCallBuf), "%s %d", *funcName, f);

	FOutputDeviceNull ar;
	c->CallFunctionByNameWithArguments(ANSI_TO_TCHAR(funcCallBuf), ar, NULL, true);
}

void UTDLSurvivorFastCache::CallActorFuncFloatParam(AActor * c, FString funcName, float f)
{
	_snprintf(funcCallBuf, sizeof(funcCallBuf), "%s %f", *funcName, f);

	FOutputDeviceNull ar;
	c->CallFunctionByNameWithArguments(ANSI_TO_TCHAR(funcCallBuf), ar, NULL, true);
}

void UTDLSurvivorFastCache::CallActorFuncFloatIntParam(AActor * c, FString funcName, float f, int32 n)
{
	_snprintf(funcCallBuf, sizeof(funcCallBuf), "%s %f %d", *funcName, f, n);

	FOutputDeviceNull ar;
	c->CallFunctionByNameWithArguments(ANSI_TO_TCHAR(funcCallBuf), ar, NULL, true);
}

```

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 22, 2015, 1:33pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/12 "2015-12-22T13:33:41Z")

</div>

Is there a way to do this for a AActor parameter?

---

<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:** [April 27, 2017, 3:19am UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/13 "2017-04-27T03:19:35Z")

</div>

This is a better solution to the problem of a callable blueprint function. My above answer is also useful but in a slightly different scenario. I suggest trying this solution first, and my solution second.

---

<div class="post-metadata">

**Author:** ![guyun008](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@guyun008](https://forums.unrealengine.com/u/guyun008)\
**Post date:** [August 18, 2017, 8:16am UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/14 "2017-08-18T08:16:51Z")

</div>

Do not Play matinee By C++,if not packet project will fail!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0b7eaa0d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0b7eaa0d](https://forums.unrealengine.com/u/anonymous_user_0b7eaa0d)\
**Post date:** [November 28, 2018, 3:54pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/15 "2018-11-28T15:54:09Z")

</div>

In case you google this and actually want to do what the OP states in the title, here is some code:

**To Call Blueprint function node from C++ :**

1 - Expose a function handle in C++ Header:

```
UFUNCTION(BlueprintImplementableEvent, Category = "AI") 
void StartPartrolling();

```

2 - Add the function node to the blueprint event graph

In this example right click on event graph and search for “event start patrolling” and connect it up to whatever you wan to run

![260784-capture.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/0/8/908dbc694e9f97d98455abbff1da18b2a1d42100.jpeg)

3 - Call the function StartPartrolling() from your C++ Code

4 - Profit

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [January 14, 2019, 4:48pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/16 "2019-01-14T16:48:05Z")

</div>

This should be on the MAIN CPP DOC PAGE !!!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0b7eaa0d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0b7eaa0d](https://forums.unrealengine.com/u/anonymous_user_0b7eaa0d)\
**Post date:** [January 14, 2019, 7:28pm UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/17 "2019-01-14T19:28:48Z")

</div>

I haven’t tested it, but I assume If the function name you pass into CallFunctionByNameWithArguments() is misspelled or doesn’t exist the compiler (and IDE) won’t catch it, and you’ll get a run-time error / crash? I’d prefer to use a technique that would be picked up before that (for example the technique I posted below) by the complier or IDE. IMHO leveraging the power of the IDE will increase your development speed, accuracy and quality.

---

<div class="post-metadata">

**Author:** ![vdlmrc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vdlmrc](https://forums.unrealengine.com/u/vdlmrc)\
**Post date:** [January 29, 2019, 11:39am UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/18 "2019-01-29T11:39:21Z")

</div>

That’s clearly the easiest and cleanest way to do it. Thanks for that!

---

<div class="post-metadata">

**Author:** ![CppCode](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CppCode](https://forums.unrealengine.com/u/CppCode)\
**Post date:** [January 31, 2019, 8:15am UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/19 "2019-01-31T08:15:55Z")

</div>

UFUnction\* Func = Obj-\>GetClass()-\>FindFunction(FName(“FuncName”));  
if(Func == nullptr){return;}

```
FStructOnScope FuncParam(Func);
UProperty* ReturnProp = nullptr;

for (TFieldIterator<UProperty> It(Func); It; ++It)
   {
	UProperty* Prop = *It;
	if (Prop->HasAnyPropertyFlags(CPF_ReturnParm))
	{
		ReturnProp = Prop;
	}
	else
	{
		//FillParam here			
        }
}

Obj->ProcessEvent(Func, FuncParam.GetStructMemory());
```

---

<div class="post-metadata">

**Author:** ![jimmyt1988](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jimmyt1988](https://forums.unrealengine.com/u/jimmyt1988)\
**Post date:** [May 19, 2019, 11:32am UTC](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/20 "2019-05-19T11:32:26Z")

</div>

I noticed that in some cases, the UFUNCTION is called on the next tick. This causes problems for state machines. Do you know how to ensure a UFUNCTION is called in the same tick as the caller?

[Next page](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119.md?page=2)
