If we are reviving necro posts, I’d like to add that Lambdas are criminally underrated. Basically, they allow you to write a function inside another function.
// example variables that are outside the lambda
FString MyString = TEXT("blabla");
int32 MyInt = 100;
// creating the lambda timer delegate
FTimerDelegate MyTimerDelegate = FTimerDelegate::CreateLambda([MyString, MyInt]()
{
// code here...
// if you want to use variables that are outside the lambda, make sure to include them in the [].
// otherwise, you'll get a compile error.
UE_LOG(LogTemp, Display, TEXT("MyString = %s"), *MyString);
UE_LOG(LogTemp, Display, TEXT("MyInt = %d"), MyInt);
});
// binding the timer
GetWorld()->GetTimerManager().SetTimer(MyTimerHandle, MyTimerDelegate, 1.0, true);