Trying to set a timer for stamina regeneration delay

What is wrong with the code here? Im trying to use Set Timer function to set a delay when regenerating stamina but the first line of code doenst seem to work

GetWorldTimerManager().SetTimer(TimerHandle, this, &AMain::AddStamina, time);  

void AMain::AddStamina()
{
	Stamina += StaminaDrainRate* GetWorld()->GetDeltaSeconds();
}

The way I see the AddStamina() function, it’s a stamina regeneration function. But you’re saying you want a delay before it starts regenerating. So something doesn’t add up here.

My first idea of how to do it would be:

GetWorldTimerManager().SetTimer(TimerHandle, this, &AMain::StartStaminaRegeneration, time, false);

void AMain::StartStaminaRegeneration()
{
    bStaminaRegenerates = true;
}

AMain::Tick(float DeltaTime)
{
    if (bStaminaRegenerates)
    {
        Stamina += StaminaDrainRate * DeltaTime;
        if (Stamina >= MaxStamina)
        {
            Stamina = MaxStamina;
            bStaminaRegenerates = false;
        }
    }
}

And you set bStaminaRegenerates to false when you start sprinting again. You can use a second looping timer instead of Tick() if you like.

Thanks! It worked