How can I delay within a for loop?

I am trying to add a delay for each loop of a for loop in c++.

void UTankAimingComponent::Reload()
{
	RoundsLoaded = 0;
	for (int i = 0; i < MaxRoundsLoadable; i++)
	{
		float DelayTime = ReloadTimeInSeconds / MaxRoundsLoadable;

		// TODO Delay by DelayTime

		RoundsLoaded++;
		RoundsLeft--;

		if (!ensure(ReloadSound)) return;
		UGameplayStatics::PlaySoundAtLocation(this, ReloadSound, Barrel->GetSocketLocation(FName("Projectile")), ReloadVolumeMultiplier, ReloadPitchMultiplier, ReloadStartTime);
	}
}

I am aware this may be doable with timers, although I feel there might be a better way. Is the only way to use timers?

Thank you

  • Dan

Thats what I am trying to find, but I am having no luck

In Blueprint, you can use the built-in function “Delay”. I think there must be an equivalent of it in the C++ framework.

I hope this might be of help, but I have not read it carefully…