Calling BP Events From CPP

There are a few ways to fire events in Blueprint but I am going to cover BlueprintImplementableEvent and BlueprintNativeEvent.

Events in Blueprint

There are a few ways to fire events in Blueprint but this page is going to cover BlueprintImplementableEvent, BlueprintNativeEvent & CallFunctionByNameWithArguments.

BlueprintImplementableEvent

This is the simplest one and it allows you to call a Blueprint event from C++. You just need to use the BlueprintImplementableEvent in the UFUNCTION macro in the header file and that's it.

[Header] UFUNCTION(BlueprintImplementableEvent) void MyBPEvent();

Which shows up in the blueprint like this:

File:BPEvent.png

Now you can call it like any other method in C++:

[CPP] void AMyEventActor::BeginPlay() { Super::BeginPlay(); MyBPEvent(); }

BlueprintNativeEvent

This one works almost identically to BlueprintImplementableEvent except that it requires a C++ function to be implemented. The native definition needs to have Implementation after it but when calling it, call the header defined function. This gives you the advantage to optionally run the behavior of the native method if you add a call to the parent function.

[Header] UFUNCTION(BlueprintNativeEvent) void MyNativeEvent();
[CPP] void AMyEventActor::BeginPlay() { Super::BeginPlay(); MyNativeEvent(); } void AMyEventActor::MyNativeEvent_Implementation() { UE_LOG(LogTemp, Warning, TEXT("Doing some work here")); }

File:NativeEvent.png

When it runs the output is:

File:Output.png

CallFunctionByNameWithArguments

If the BP inherits from a C++ class like an actor or any UObject. Its possible to call functions or events from C++ to BP. As well as pass arguments as const TCHAR*, each argument is assessed as a space. Meaning the first string will be used to identify the function and any additional strings are considered parameters, with a space indicating that its a different parameter.

FOutputDeviceNull OutputDeviceNull; const TCHAR* CmdAndParams = TEXT("Foo 1 2 3") this->CallFunctionByNameWithArguments(CmdAndParams, OutputDeviceNull, nullptr, true);

To use the parameters inside a BP the function or custom event has to have the input pins of type string, from there you can cast them to any other type.

Its possible to also call the function with no arguments, simply passing in the event/function name will work too:

FOutputDeviceNull OutputDeviceNull; this->CallFunctionByNameWithArguments(TEXT("Foo"), OutputDeviceNull, nullptr, true);
Updated ago