Hello Dear Community,
I want to add bonuses to my character individually seperated from others which took 10 secs.
Assume that you character collecting bonus, like 2x point and 2x speed.
2x point collection is in time T1
2x speed collection is in time T2
Since you collect both of them between (T2 - T1) = 5 seconds. So 2x point bonus will deplete after 5 second after you collect 2x speed bonus.
For that purpose I have created a TMap which includes TimerDelegate and its own deplete time as float.
FTimerHandle TimerHandle;
FTimerDelegate TimerDelegate;
FBonusTimerHandle* BonusTimerDelegate = new FBonusTimerHandle();
BonusTimerDelegate->ActiveTimerHandle = TimerHandle;
BonusTimerDelegate->RemainingTime = BonusDuration;
TimerDelegate.BindUFunction(this, FName("DepleteBonus"), BonusType);
GetWorldTimerManager().SetTimer(TimerHandle, TimerDelegate, 0.01f, true);
here is my deplete function
void AEBallGameMode::DepleteBonus(ConsumableBonusType BonusType)
{
auto* ActivePowerUp = &(ActivePowerUps[BonusType]);
ActivePowerUp->RemainingTime -= 0.01f;
UE_LOG(LogTemp, Warning, TEXT("--Depleting Bonus : %f--"), ActivePowerUp->RemainingTime);
if (ActivePowerUp->RemainingTime <= 0.f)
{
GetWorldTimerManager().ClearTimer(ActivePowerUp->ActiveTimerHandle);
RemoveBonus(BonusType);
AddBonusWidget(BonusType, false);
}
}
Question is ClearTimer is not working. Why?