Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Call Blueprint functions from C++

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

Product Version: Not Selected
more ▼

asked Oct 14 '14 at 06:20 PM in C++ Programming

avatar image

46 2 4 6

avatar image Doug E ♦♦ STAFF Oct 14 '14 at 06:52 PM

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


Doug Wilson

avatar image theJulman Oct 15 '14 at 10:43 AM

So thats how my PlayerCharacter.cpp looks like:

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

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: alt text

blueprint.png (72.8 kB)
avatar image SND R Keene Jun 06 '15 at 08:09 PM

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);

alt text

avatar image Two-faced Jan 14 '19 at 04:48 PM

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

avatar image LonnyKee Jan 14 '19 at 07:28 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

5 answers: sort voted first

//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


//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(); "

more ▼

answered Oct 15 '14 at 04:53 AM

avatar image

9.6k 320 205 449

avatar image theJulman Oct 15 '14 at 11:50 AM

Oke thanks this answer worked for me :)

avatar image yurembo Nov 20 '14 at 09:45 AM

How do you make this?

avatar image Ciprian At Facerig Mar 16 '15 at 02:41 PM

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

avatar image Doug E ♦♦ STAFF Mar 16 '15 at 06:12 PM

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.

avatar image SND R Keene Apr 27 '17 at 03:19 AM

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.

avatar image jimmyt1988 May 19 '19 at 11:32 AM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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"
 class TDL_API UTDLSurvivorFastCache : public UBlueprintFunctionLibrary
     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

alt text

alt text

more ▼

answered Jun 06 '15 at 07:35 PM

avatar image

SND R Keene
963 31 120 113

avatar image SND R Keene Jun 06 '15 at 08:26 PM

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);
avatar image xlar8or Dec 22 '15 at 01:33 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

alt text

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

4 - Profit

capture.jpg (32.9 kB)
more ▼

answered Nov 28 '18 at 03:54 PM

avatar image

26 1 4

avatar image vdlmrc Jan 29 '19 at 11:39 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
 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;
         //FillParam here            
 Obj->ProcessEvent(Func, FuncParam.GetStructMemory());
more ▼

answered Jan 31 '19 at 08:15 AM

avatar image

47 3 5 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Aug 18 '17 at 08:16 AM

avatar image

6 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question