Struggling to Save/Load a Timer variable

I have implemented a fully functional Save/Load mechanic to my game.

At the moment it grabs the current variables on Save and successfully sets them on Load:

Player Position
Health
Score

I have a 4th variable which is a timer, currently displayed on the HUD. This data is within a Widget Blueprint.

I’m struggling to successfully grab the timer variable from the Widget Blueprint, store it in the Save Game file, and load it. I have tried various methods but can’t seem to solve it myself, so I’m coming to this amazing community to seek some advice/help on the matter.

Thanks in advance :slight_smile:

Could you show your attempt on saving that variable named “Time”? I think it shouldn’t be any different from the others. Did you make sure to set your variable to the saved time variable upon loading?

I sense it’s just about accessing the widget.

  • in which BP do you create the timer?
  • in which BP do you handle loading / saving?

Once you know these two :point_up:, you can tell the engine where to look for the data.

The timer was created and stored in the WBP_Timer.

Saving and Loading takes place in the blueprint of the first person character.

Where, in which BP? In which BP do you Create WidgetSet WBP_Timer → Add to Viewport? Your save game system must access the BP that stores the WBP_Timer widget ref. Or, perhaps, you use a widget component to instantiate the timer?

I have a WBP_HUD, which has the WBP_Score and WBP_Timer added under the Hierarchy.

BP_FirstPersonGameMode casts the HUD:

Reference the widget:

You can right click the Return Value pin and Promote to Variable to simplify this step:

Then, Get Game ModeCast To BP_FirstPersonGameMode → Get (New Var) reference → Get timer float


Not sure what you mean by this, tbh.

When I said cast, I meant “Add to viewport”

As it currently stands, WBP_Timer has been dragged and dropped into WBP_Hud as an element under the hierarchy.

Would it be worthwhile removing WBP_Timer from the hierarchy of WBP_Hud, and have WBP_Timer added to viewport as a standalone Widget?

Does not matter. Access hud => acces timer widget.

You truly are a Community Hero! :innocent:

Thank you so much!

I now have my time variable correctly being saved and loaded!

I’m sure there will be past/present/future people that may at some point come across a similar issue, so I am sharing the code to help them :slight_smile:

Saving:

Loading:

@Everynone You have made me evening, thanks again!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.