Download

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();
}



im doing everything right? can i do it without timer?

.h



#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CallFunctionByName.generated.h"


UCLASS()
class PS1_API UCallFunctionByName : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:
    UFUNCTION(BlueprintCallable, meta=(DisplayName = "Call Function by Name", DefaultToSelf = "Object"), Category="Custom C++")
static bool CallFunctionByName(UObject* Object, FString FunctionName);


};


.cpp



#include "CallFunctionByName.h"

bool UCallFunctionByName::CallFunctionByName(UObject * Object, FString FunctionName)
{
    FName const FunctionFName(*FunctionName);
    if (Object)
    {
        {
        UFunction* const func = Object->FindFunction(FunctionFName);
        if(func && func->ParmsSize == 0)
            {
            FTimerDelegate Delegate;
            Delegate.BindUFunction(Object, FunctionFName);
            Delegate.Execute();
            return true; // Worked.
            }
    return false; // Didn't Work.

        }
    }
    return false; // Didn't Work.
}


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); }

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?