Managing skills replenish/deplenish in Tick function

Hello everyone, I added two skills for my character, i.e. activating a shield and a speed boost.
Both those skills can’t be active forever, but only for a certain duration, and they recharge while not being used.
I’m currently handling it by calling the following function in the Tick function (same way for the boost):

void MyPawn::ManageCurrentShield()
    if (bShieldActive)
        if ((CurrentShield = FMath::Clamp(CurrentShield - 0.2f, 0.f,
                                          MaximumShield)) == 0.f)
        CurrentShield = FMath::Clamp(CurrentShield + 0.1f, 0.f, MaximumShield);

My question is: is this a good practice? Or should I handle stuff like this in a different way?
Thank you in advance!

You really only have two options for things like this:

  • Handle it in a Tick function
  • Use Timers

I’d say Tick is fine here, however your changes to CurrentShield is framerate-dependent. If you are absolutely 100% sure that you are going to force the game to use a fixed FPS and it can maintain that FPS then I suppose that’s fine but I wouldn’t recommend doing that.

So I’d suggest expressing your recharge/depletion rate in x units per second, e.g. recharge 10 shield points per second when not using it and drain 20 points per second when using it.
Then you need to take into account the DeltaTime param passed into Tick when you make the adjustments, e.g.

CurrentShield = FMath::Clamp(CurrentShield + DeltaTime * (bShieldActive ? -20.f : 10.f), 0.f, MaximumShield)

Thanks, that’s exactly what I as looking for! Really appreciate your clarification.
Have a good day!