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

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!

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.

1 Like

Where can I find examples?

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

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

1 Like

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

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

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

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.

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

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

but it’s not work