exec local function by name without params

have any ideas how to create sucha bp block?

I didn’t understood the question… :confused:

Do you mean something like this?




UFunction* const func = [Your actor or whatever object]->FindFunction("Your function name");
if(func && func->ParmsSize == 0)
{
    FTimerDelegate Delegate;
    Delegate.BindUFunction([Your actor or whatever object] , "Your function name");
    Delegate.Execute();
}



Ew. Don’t do that. What’s wrong with using normal timers? There are plenty of overloads for this.



GetWorld()->GetTimerManager().SetTimer(FTimerHandle_MyTimer, this, &AMyObject::MyFunctionToCall, Delay, false, Delay);



if(func && func->ParmsSize == 0) {   Object->ProcessEvent(func, nullptr); }

1 Like

works perfect, ty.

This post was made so long ago that I am not sure if anyone would reply but.

What if I wanted to call functions by name, and those functions do different stuff but overall only need two parameters, an Actor and an Integer.
Is there anyway I could implement this using the code made above?

Here is a generic way to call ufunction with any number of params:

	// Calls ufunction (with no return type) or event by name on object with parameters. Num parameters must match and be in order of function signature, f-ction will not
	// be called if parameter is unable to convert e.g - 'dupa' cant convert to float. Can be used to call f-ctions without parameters. Was tested with booleans, floats, ints, strings
	// Returns true if f-ction was called successfully 
	UFUNCTION(BlueprintCallable, Category = Reflection)
		static bool CallFunctionByNameWithParameters(UObject* ObjPtr, FName FunctionName, const TArray<FString>& Parameters);
bool UGGUtilitiesFunctionLibrary::CallFunctionByNameWithParameters(UObject* ObjPtr, FName FunctionName, const TArray<FString>& Parameters)
{
	if (!IsValid(ObjPtr))
		return false;

	FString Command = FunctionName.ToString();
	for (FString Param : Parameters)
		Command += (" " + Param);

	FOutputDeviceNull Ar;
	return ObjPtr->CallFunctionByNameWithArguments(*Command, Ar, nullptr, true);
}

e.g: CallFunctionByNameWithParameters(ActorPtr, “TestFunction”, {“1.13”, “124”, “hello”})
see
https://answers.unrealengine.com/questions/7732/a-sample-for-calling-a-ufunction-with-reflection.html

1 Like