I have declared these in my ATurret.h
FTimerHandle MissileTimerHandle;
bool bAllowMissileFire;
float MissileReloadTime;
This is in my ATurret::BeginPlay()
bAllowMissileFire = true;
MissileReloadTime = 1.0f;
This is my ATurret::Tick
MissileFire(DeltaTime);
GetWorld()->GetTimerManager().Tick(DeltaTime);
UE_LOG(LogTemp, Warning, TEXT("Reload Time Remaining: %f"), GetWorld()->GetTimerManager().GetTimerRemaining(MissileTimerHandle));
UE_LOG(LogTemp, Warning, TEXT("Reload Timer UnPaused: %d"), GetWorld()->GetTimerManager().IsTimerPaused(MissileTimerHandle));
And finally these are the function definitions
void ATurret::MissileFire(float DeltaTime)
{
if (!bAllowMissileFire)
{
GetWorld()->GetTimerManager().SetTimer(MissileTimerHandle, this, &ATurret::ReloadMissile, MissileReloadTime);
GetWorld()->GetTimerManager().UnPauseTimer(MissileTimerHandle);
UE_LOG(LogTemp, Warning, TEXT("Reload Timer UnPaused: %d"), GetWorld()->GetTimerManager().IsTimerPaused(MissileTimerHandle));
}
if (ParentTank->TankInput.Fire1 && bAllowMissileFire)
{
FVector FireLocation = TurretSprite->GetSocketLocation(TEXT("BarrelEnd"));
FRotator FireRotation = TurretDirection->GetComponentRotation();
SpawnMissileActor(FireLocation, FireRotation);
bAllowMissileFire = false;
}
}
void ATurret::ReloadMissile()
{
bAllowMissileFire = true;
GetWorld()->GetTimerManager().ClearTimer(MissileTimerHandle);
UE_LOG(LogTemp, Warning, TEXT("Missile Reloaded!"));
}
I just can’t seem to make the timer tick. Which means after the first missile is fired, the turret can’t fire any following missiles. I’ve tried all I can and this code is the one I’ve tried last. This is the output I get
Could you explain to me how to solve this issue? Thank you for taking the trouble people!