How to perform set timer multiple times without timer handles being replaced/reset before they are cleared and invalidated?

In Unreal engine C++, the documentation for FTimerManager::SetTimer says - “Sets a timer to call the given native function at a set interval. If a timer is already set for this handle, it will replace the current timer.”

I have a method - apply_burn_damage_for_duration(). If this happens for a duration of 5 seconds, and before the timer ends, if I call the same method again, the timer is replaced.

How to perform apply_burn_damage_for_duration() in such a way, that timer handles are not reset for each function call and independently handle their function delegates?
How to achieve that kind of “stacking” effect? (I do not wish to use ActorComponents for each burn damage function call).

Just create a new handle struct with each burn. If you need it for something then just return it in the AddBurn function.

void AMyCharacter::AddBurn() {	
	FTimerHandle BurnTimer;
	if (UWorld* World = GetWorld()) {
		World->GetTimerManager().SetTimer(BurnTimer, this, &AMyCharacter::Apply_burn_damage_for_duration, 2);
	}
}

void AMyCharacter::Apply_burn_damage_for_duration() 
{
	GEngine->AddOnScreenDebugMessage(-1,1,FColor::Orange, ("BURN"));
}

example actor is AMyCharacter in this case, replace it with your own.

Thanks! Worked.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.