SmallShank
(SmallShank)
November 12, 2024, 4:52pm
1
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
VisAgilis
(Vis Agilis)
November 12, 2024, 4:58pm
2
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?
Everynone
(Everynone)
November 12, 2024, 5:16pm
3
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 , you can tell the engine where to look for the data.
SmallShank
(SmallShank)
November 12, 2024, 5:27pm
4
The timer was created and stored in the WBP_Timer.
Saving and Loading takes place in the blueprint of the first person character.
Everynone
(Everynone)
November 12, 2024, 5:29pm
5
Where, in which BP? In which BP do you Create Widget
→ Set
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?
SmallShank
(SmallShank)
November 12, 2024, 6:15pm
6
I have a WBP_HUD, which has the WBP_Score and WBP_Timer added under the Hierarchy.
BP_FirstPersonGameMode casts the HUD:
Everynone
(Everynone)
November 12, 2024, 6:16pm
7
Reference the widget:
You can right click the Return Value
pin and Promote to Variable
to simplify this step:
Then, Get Game Mode
→ Cast To
BP_FirstPersonGameMode → Get
(New Var) reference → Get
timer float
Not sure what you mean by this, tbh.
SmallShank
(SmallShank)
November 12, 2024, 6:45pm
8
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?
Everynone
(Everynone)
November 12, 2024, 9:16pm
9
Does not matter. Access hud => acces timer widget.
SmallShank
(SmallShank)
November 12, 2024, 9:46pm
10
You truly are a Community Hero!
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
Saving:
Loading:
@Everynone You have made me evening, thanks again!
1 Like
system
(system)
Closed
December 12, 2024, 9:47pm
11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.