Create Function That Takes Events/functions as parameters.

Please, I’ve been hard-stucked on this for a Day. Is it not possible at all to declare a callback and assign it as a Blueprint parameter?? I desperately need this, and I’ve no problem coding in C++.

I’ve tried:


// Class.h
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnEachEntity, AEntity*, Entity);
...

UFUNCTION(BlueprintCallable, Category = "EntitiesSet") void ForEach(FOnEachEntity Callback) {
    for (auto& Entity : Entities)
    {
    UE_LOG(LogTemp, Warning, TEXT("HERE"));
    //Callback.Execute(Entity); // How to invoke this?
    }
} // This approach crashes as I try to run the function ForEach


// Attempt2.h
UFUNCTION(BlueprintCallable, Category = "EntitiesSet") void ForEach(TFunctionRef<void(AEntity* Entity)> Callback) {
    for (auto& Entity : Entities)
    {
    UE_LOG(LogTemp, Warning, TEXT("HERE"));
    //Callback(Entity); // I can't compile, because Callback is not a UPROPERTY, UFUNCTION or UENUM
    }
}


This is just a trivial example of what I want to achieve, for demo purposes. I’m looking for a way to achieve patterns like map-reduce and use them in many other places. I just want functional programming to be a thing