Skip to content

Instantly share code, notes, and snippets.

@gamerxl
Last active October 2, 2023 10:51
Show Gist options
  • Save gamerxl/23c7110e5a0c61eeeb74c27cc71897a5 to your computer and use it in GitHub Desktop.
Save gamerxl/23c7110e5a0c61eeeb74c27cc71897a5 to your computer and use it in GitHub Desktop.
Example for calling a blueprint event / function from c++ in unreal engine 4.
// This example shows how to call a blueprint event / function from c++ in unreal engine 4.
// In this example we call a blueprint event named "ServerRequestPossess" (see below).
// The current character for instance.
// This character must be implemented in blueprint and provides the blueprint event named "ServerRequestPossess".
ACharacter* CurrentCharacter = <instance of ACharacter>;
// Just an another character. It could by any object.
ACharacter* AnotherCharacter = Cast<class ACharacter>(Hit.Actor);
if (AnotherCharacter == nullptr)
{
return;
}
// ServerRequestPossess is a blueprint implemented event.
// The event has one input parameter of type "Character".
UFunction* Function = CurrentCharacter->GetClass()->FindFunctionByName(FName("ServerRequestPossess"));
if (Function == nullptr)
{
return;
}
// Parameters of the event.
// In this case the structure contains only the one input parameter of type "Character" as mentioned above.
struct FLocalParameters
{
class ACharacter* PlayerCharacter;
};
FLocalParameters Parameters;
Parameters.PlayerCharacter = AnotherCharacter;
CurrentCharacter->ProcessEvent(Function, &Parameters);
@Soaltino
Copy link

Soaltino commented Dec 7, 2021

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment