How to setup the FLatentActionInfo?

I know the most easy way to do a delay(like we do in BP) in c++ is to set a timer, but a timer doesnt work exactly like the delay fuction, and this is why i´m trying to use delay in c++.
First, is it possible to use delay from the KismetSystemLibrary in a c++ class (AActor, ACharacter…)?
Second, if yes, how do i make the setup in this case? :

Third, if not, why not? Cause that doesnt really make sense to be so easy in BP, and such a challenge in c++ since we can call it from that library.

Thanks everyone…
PS This is just a test, to know how it works in c++, if it is possible to do it in it.

Looking into FLatentActionInfo, the linkage parameter might be troublesome in C++, but I haven’t tried it YMMV. Otherwise you set the struct parameters, CallbackTarget = the UObject which contains the function, e.g. reference to this within your member function calls, then for ExecutionFunction write out your function name in FName format. You can probably leave Linkage and UUID in their default values.

You can see the source of the delay function right here https://github.com/EpicGames/UnrealEngine/blob/a07fbf5ed73138b7af773a6acfbe1693a234b582/Engine/Source/Runtime/Engine/Private/KismetSystemLibrary.cpp

Let me know if your tests work, I’m curious :slight_smile:

Hi, Invius. I faced a similar task.
Use Timers:

GetWorld()->GetTimerManager().SetTimer(…)

GetWorld()->GetTimerManager().ClearTimer(…)

I can created simple examples if needed?

CallbackTarget-> needs to be the base classe that declares the function?
ExecutionFunction-> Fname format, never heard of it, can you give me one exemple?

I´ve found something interesting FTicker, it supose to create a delay/interval with the addticker fuction, but i dont know how that really works, so i skipped it.

Thanks man, i know how to do use timer, the real problem right here is to know why we cant use the delay function, that really wierd since BP can use, and we can call from KismetSystemLibrary.

One more thing, GetFunctionCallSpace, does it have anything to do with linkage?

There is also a debate in this post, if anyone could help, it would be really awesome.

Hi, Invius. Try this example:

MyActor.h

UFUNCTION(BlueprintCallable, Category = "Custom")
void TestCall();

MyActor.cpp

void AMyActor::BeginPlay()
{
	Super::BeginPlay();

	FLatentActionInfo LatentActionInfo;
	LatentActionInfo.CallbackTarget = this;
	LatentActionInfo.ExecutionFunction = "TestCall";
	LatentActionInfo.UUID = 123;
	LatentActionInfo.Linkage = 0;
	
	UKismetSystemLibrary::Delay(this, 5.0f, LatentActionInfo);
}

// Call function must be BlueprintCallable!

void AMyActor::TestCall()
{
if (GEngine)
	GEngine->AddOnScreenDebugMessage(-1, INFINITE, FColor::Black, TEXT("AMyActor::TestCall"));
}

For me it worked.)

6 Likes

That’s right !!
thank you.
I need It.

I was only able to get this working when linkage = 1. Setting it to 0 does not trigger anything. Aside from that, the answer here worked.

Can’t figure out how to pass parameters to the function, though.

Big thanks to cridia from this thread: