Chest 6 hour cooldown and create cooldown

I have a loot box in my game and I want this box to be able to be opened every 6 hours.
How do I create the timer for this?
So far I haven’t found a way to create a timer that expires.

When you close the game the time is saved and when you reopen the game the elapsed time is deducted.

Hey @NotPasi_TV!

You should be able to save the old time, reduce the time by subtracting the new time, and run a “Set Timer by Event” somewhere for this!

Then you’d just pass in the new “Remaining Time” when the timer is run (on game restart), then when the timer is elapsed use a CUSTOM EVENT to reset the “bChestAvailable” boolean! :slight_smile:

Hope that helps! Anything more and we’re gonna have to see some code, though! :slight_smile:

You could also create a GameInstance or World subsystem that handles the chest timers.
Have the chest record its last opened time in the subsystem, and have the chest check on every interaction or based on distance (if you want to set the visual to opened/closed).

Whenever you close and reopen the game, have the subsystem save/load the data and if necessary pre-calculate the time the chest should be available again.

As for the timer. Have a timer in your subsystem run to the next first time, invoke the delegate and reset timer to the next. That way you also have just one timer running the whole subsystem.

Hope this helps.

And how do I display the timer for the player?

Well, that would be dependent on your code you’ve already implemented, where you want it to show up, et cetera. But what I can tell you that you’ll need regardless is it’ll be a widget, with a horizontal box containing three text boxes:
“Hours”, “:”, “minutes”, “:”, “seconds”.

Then you’ll bind hours, minutes, and seconds to individual functions. Then get those values from wherever they are located. :slight_smile:

1 Like