C++ How I made timers work when game paused

Hello everyone

What are you thoughts about how I made timets work even when game is paused?
Here is the code

class APausedTimerManagerTicker : public AActor
	virtual void Tick(float DeltaSeconds) override;

inline APausedTimerManagerTicker::APausedTimerManagerTicker()
	PrimaryActorTick.bCanEverTick = true;
	PrimaryActorTick.bTickEvenWhenPaused = true;

inline void APausedTimerManagerTicker::Tick(float DeltaSeconds)
	if(GetWorld() && GetWorld()->IsPaused())

That seems like a clever solution. Does it work?

Yes it does work, but . . .

In my game I have resources like metal, wood, that are being collected every second. And they work using timers, and it’s obvious that they should be paused when game is paused. But when this class is used they collect resources even when game is paused, which is wrong.

Now I am thinking about writing own TimerManager that will allow to mark any single Timer as TickWhenPause = true, so I could controll which timers I want to tick when paused and which ones I dont want to.

Yes I am a newbie in UE4 and maybe there exist more correct solution, but I am not aware of it right now(((

I honestly think you’d be well placed to turn this into a pull request for the engine on github - This seems like a feature that a lot of people would find very useful

Really? I think you overestimating me)

Hi, about writing your own TimerManager that will allow any single Timer works when game pause, do you have any follow-up solution? I would like to know, thanks!

Unless you’re going to override TimerManager and build it o ut to handle that sort of thing, because you need it a lot for some reason, then it’s easiest just to do a Tick in the object that needs it