How to save total played time?

I’ve been banging my head against the wall for several hours now but I can’t figure this out. Yes I’ve searched on google many times but something isn’t clicking.

I want to save total play time across sessions. I’m using a Get Real Time Seconds node and adding to my Total Time Played variable in my savegame blueprint, but every time I save it adds the total time since the session started, not total time since I saved.

I just can’t figure this out, and it sounds really simple. Ideas?

You’ve basically already answered your own question:

Whenever you save, keep track of the last save time. Then, on the next save, subtract the last save time from the current time and that will give you the time since the last save. Then add that to your savegame variable.
So it’s timeSinceLastSave = currentSaveTime - lastSaveTime.
Don’t save the last save time, though, cuz that will reset between sessions.

Also, Get Real Time Seconds gets the time even when paused. If you don’t want that, use Get Time Seconds instead.


hey, thanks

yeah I figured I should do something like that but I can’t find out how, I’m probably just exhausted but I’m not seeing how I can save time since the last save.

I already turned off my computer but let me give another go mentally, before bed. so both lastSaveTime and currentSaveTime vars start as 0, so timeSinceLastSave will also be 0 at first.

Then when I save, first lastSaveTime = currentSaveTime, and then currentSaveTime = Get Time Seconds? and after that, timeSinceLastSave = currentSaveTime - lastSaveTime? will this work?

If so, then I set my savegame totalTimePlayed = totalTimePlayed + timeSinceLastSave?

I’m sorry, my brain is starting to fail, but I really want to try it out in the morning

You basically got it, but I just realized there’s a simpler way to do it, lol (tested & works):

It just adds the time of the current session to the time of the last session.


ok so my logic worked, thanks to you!

however I don’t think I can use your code above since I’m saving my game from the pause menu widget bp, so there’s no begin play, only construct. Could it work?

1 Like

The begin play was only used to load the last save; it isn’t necessary, so you can do it from anywhere. Just make sure you load the last save only once per session before saving a new one so you can get the correct LastTotalTimePlayed.

1 Like