Last active
December 26, 2024 09:51
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks