Example Class:
UCLASS()
class TESTING_API UMyObject : public UObject {
GENERATED_BODY()
public:
UFUNCTION()
void MyMethod(){ UE_LOG(LogTemp, Warning, TEXT("MyMethod Invoked")); }
UFUNCTION()
void MyMethodArgs(int32 Value){ UE_LOG(LogTemp, Warning, TEXT("MyMethodArgs called with = %d"), Value); }
};
Invoking UFunction:
// Creating Object
UMyObject* MyObj = NewObject<UMyObject>(this, TEXT("MyObject"));
// Invoking function without arguments
FName MethodName = FName(TEXT("MyMethod"));
UFunction* Func = MyObj->FindFunction(MethodName);
if (Func) {
MyObj->ProcessEvent(Func, nullptr);
}
// Invoking function with arguments
FName MethodArgsName = FName(TEXT("MyMethodArgs"));
UFunction* FuncArgs = MyObj->FindFunction(MethodArgsName);
if (FuncArgs) {
struct
{
int32 Value;
} ParamStruct;
ParamStruct.Value = 56;
MyObj->ProcessEvent(FuncArgs, &ParamStruct);
}