Change tick delay?

Hello,

I am creating a C++ class for a capture-the-flag zone.
I want to call every 0.1s (or any other value) a function that checks who is inside the zone, instead of every frame with the current tick. How can I do this?

Currently my .h is :

UCLASS()
class VRFRACTURE_API AFlagObjective : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AFlagObjective();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

UFUNCTION()
void Boucle();

float DelaiMajCapture;	//Définit toutes les cb de secondes la barre de capture est mise à jour
};

and my .cpp is :

// Sets default values
AFlagObjective::AFlagObjective()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;	//Cette ligne semble ne servir à rien
	SetActorTickEnabled(true);				//Cette ligne semble ne servir à rien

	DelaiMajCapture = 0.1;	//Définit toutes les cb de secondes la barre de capture est mise à jour    	
}

// Called when the game starts or when spawned
void AFlagObjective::BeginPlay()
{
	PrimaryActorTick.bCanEverTick = true;
	SetActorTickEnabled(true);

	Super::BeginPlay();

	Boucle();
}


// Called every frame
void AFlagObjective::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

(I deleted all parts of code not related to my question)

DelaiMajCapture contains the delay I would like between every tick for this class : 0,1s.

I’ve seen on Google that making a timer and an event could be better, but I don’t know how to do this with C++. I only found documentation for blueprints.

So I found documentation about timers.

But I have a problem. All examples I found to repeat a function with a timer were written like this :

	GetWorldTimerManager().SetTimer(MemberTimerHandle, this, &ATimerActor::RepeatingFunction, 2.0f, true, 5.0f);

BUT I would like to get the value my RepeatingFunction returns. So I tried to write :

	GetWorldTimerManager().SetTimer(MemberTimerHandle, this, StatutSauvegarde = &AFlagObjective::WhoDominatesFlag, 0.5f, true, 0.0f);

but the compiler doesn’t like this part : StatutSauvegarde = &AFlagObjective::WhoDominatesFlag

I also tried StatutSauvegarde = AFlagObjective::WhoDominatesFlag() and received less insults from the compiler, but there is still one blocking me :

C:\UE4_forks\Unreal_Projects\VRFracture\Source\VRFracture\FlagObjective.cpp(43) : error C2664: 'void FTimerManager::SetTimer(FTimerHandle &,TFunction &&,float,bool,float)'?: impossible de convertir l'argument 3 de 'int32' en 'void (__cdecl AFlagObjective::* )(void)

StatutSauvegarde = GetWorldTimerManager().SetTimer(MemberTimerHandle, this, &AFlagObjective::WhoDominatesFlag, 0.5f, true, 0.0f);

This code still does not compile…

 C:\UE4_forks\Unreal_Projects\VRFracture\Source\VRFracture\FlagObjective.cpp(43) : error C2664: 'void FTimerManager::SetTimer(FTimerHandle &,TFunction<void (void)> &&,float,bool,float)'?: impossible de convertir l'argument 3 de 'uint32 (__cdecl AFlagObjective::* )(void)' en 'void (__cdecl AFlagObjective::* )(void)'
  C:\UE4_forks\Unreal_Projects\VRFracture\Source\VRFracture\FlagObjective.cpp(43): note: Les types point?s n'ont aucun rapport entre eux?; conversion n?cessitant reinterpret_cast, cast de style C ou cast de style fonction

SetActorTickInterval
(
float TickInterval
)
call this in beginplay.

It looks like it works, however my code GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Purple, "Team dominante : 1"); located in the Tick() function is supposed to be called every tick, which happens, but for some reason it disappears instantly before coming back, and sometimes it never came back.

It would probably not be a problem for my final use of this tick, but I am wondering why this is happening?

.h code
.cpp code

try to log StatutSauvegarde and see if it works fine

I have already done this, this code should display on screen the variable’s value every tick :

// Called when the game starts or when spawned
void AFlagObjective::BeginPlay()
{
	float DeltaTime = 1;
	SetActorTickInterval(DeltaTime);
	PrimaryActorTick.bCanEverTick = true;
	SetActorTickEnabled(true);

	Super::BeginPlay();

	EnterEffect();

	//GetWorldTimerManager().SetTimer(MemberTimerHandle, this, &AFlagObjective::WhoDominatesFlag, DelaiMajCapture, true, 1.0f);

}




// Called every frame - ACTIVE
void AFlagObjective::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	
	StatutSauvegarde = WhoDominatesFlag();

	DebugOutput = FString::FromInt(StatutSauvegarde);

	if (StatutSauvegarde == 1)
	{
		GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Purple, "Team dominante : " + DebugOutput);
	}
	
}

So the DeltaTime is set to 1s.
Every second, when I am in the capture zone, this GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Purple, "Team dominante : " + DebugOutput); is being displayed. BUT it disappears instantly.
It looks like my Tick function is correctly ticking every 1s, but something deletes the message just after it has been displayed, maybe every frame?

I also tried to use UE_LOG(LogTemp, Warning, TEXT("TEAM QUI DOMINE : %f"), *DebugOutput);

Complete function :

// Called every frame - ACTIVE
void AFlagObjective::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	
	StatutZone = WhoDominatesFlag();

	DebugOutput = FString::FromInt(StatutZone);

	GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Purple, "Team dominante : " + DebugOutput);
	UE_LOG(LogTemp, Warning, TEXT("TEAM QUI DOMINE : %f"), *DebugOutput);
	
}

But it does not work. The UE_LOG always outputs the value 0.000000 instead of the actual DebugOutput 's value.
I am sure the variable is working properly because the bugged AddOnScreenDebugMessage still shows “1” when I am in the zone, or “0” when I am outside.

Here, I am outside of the zone so the 0 value is ok :

Here, I am inside of the zone so the 0 value in the logs is NOT ok. However, the value displayed on screen every second is correct, it shows “1” :

Uuuuuups the log now works correctly :

I wrote :

UE_LOG(LogTemp, Warning, TEXT("TEAM QUI DOMINE : %f"), *DebugOutput);

But the good code is :

UE_LOG(LogTemp, Warning, TEXT("TEAM QUI DOMINE : %s"), *DebugOutput);

Anyway, that does not solve the fact my OnScreenDebugMessage gets erased all the time…