I’m trying to find out atm how I could track time while game is shut down. Like if player does something that starts a timer for and example player puts a building in to making that takes 1,5h to construct, how do I tack it so that I could A) give a push notification when the construction is ready and B) have the construction done or show correct remaining time when opening the app again?
Do I need some backend shenanigans to do this or is it possible to do this offline? The game in it self doesen’t need online so this would be not prefered…
I don’t think I understood that. I can see you’re attempting loading and saving the game 60 times per second (or more!) - during Tick. That cannot be right.
You say
when the energy ends it is impossible to play
But it seems we are accumulating energy rather than depleting it.
I did deplete energy when pressing the play button. total energy is 15. When it ends, you can’t play until you have to wait until the energy is restored, I wrote a recovery condition (if less than 15, then there is a recovery) it remains only to make a timer so that, for example, 1 energy is restored every 5 minutes and then you can play again, I’m all did except the timer. I need to make it work when the game is not running. I found that this system is done through the data type “Date time” but I do not know how to use it, unfortunately I did not find the drawings. in the 2nd screenshot of the drawing where “delay” you need something else instead, since “delay” only works when the game is running, I hope I explained it clearly. if it is not clear, I can record a video of how it works and send you a link. In general, I want energy to regenerate over time (every 5 minutes + 1 energy, up to 15), even if the game is closed.
do not use Tick + Delay, especially for this - you’re loading your game 60 times per second, flood the Delay every frame and then save the game every 30s.
create an event for saving the game
create an event for loading the game
use a timer to count the energy when the game runs
before player quits the game, save the amount of energy they had and a timestamp
when they load the game, check the amount of energy saved and calculate how much time has passed since last save
if you want to have a cap on the amount of energy that can be restored, you could clamp it
Thank you very much! it worked, but my variable stopped depleting, when you press “play”. It only restores to 15, I wrote the logic in the “player controller” and tied “load game” to the “event tick” “save game” is tied to the button, which is associated with the exit from games, right?
if I understand you correctly, then yes, I made a separate slot for loading and saving energy. but I can’t figure out what to attach “load game” to because it doesn’t work with “event begin play” but only works with “event tick”
If the player’s energy can be unlimited, just keep adding it with a timer. If there’s limit regarding how much they can regenerate while offline, clamp it: