Saving and reloading an integer?

Hi everyone!

I am kind of new here and am having serious difficulties getting something seemingly simple to function.

I have a variable thats set on my player character called TotalKills (integer) using an AddKill function call. This value is stored in a textbox on my players widget hud.

This is what I would like to have:
The player will repeat playing various levels for a high score basically.

  1. Display map name and high score while in the map. Save the TotalKills variable upon his “faked” death if he clicks the (game over) screens Retry, only if the player actually beat his/her record.
  2. Save the total kills to data before he/she quits, but only if they beat their high score, and load it on completely starting the whole game again.

Every Tutorial, or forum post or ASK I come across does not work or is dealing with things I do not need like saving position or checkpoints and even trying to remodel those tutorials to work for me are failing miserably. Ive spent the entire weekend now failing like a pr0 noob :smiley:

I do not want to use the Level Blueprint for this because i will have multiple levels and will add a scores page that shows scores from various levels to my main menu Statistics page.

Can I save the data to file…from the characters blueprint Death Event (which calls my AddKill function too)…and have it reloaded from these 2 widgets that handle either RETRY or STARTGAME.

I dont know how to display the present level name either…

Can someone assist me on this?

Saving data that should be persistent across levels is best done through the GameState class. It can be passed from map to map without being reset, and is accessible to all clients in a multiplayer game. Create your int variable there, and save your kills to the GameState :slight_smile:

Actually saving the data between game restarts is a whole other beast, and I would suggest reading these articles:

The first article is a touch more involved, but will result in a far more flexible system for you. The second one is more general-purpose, and can be done in only Blueprint.

Ok thanks for the quick reply. Honestly, I don’t know where the gamestate is…must be a blue print if you said class ill check that out, but i sort of have the feeling this is way over my head some how. I’ve managed a lot but this is like…

I checked out the blueprint version because I dont speak C++.

Even on that page half of the necessary things are so cryptically explained. First example was the “create an instance or copy”.

Where? is it just a variable called that or is it a whole blueprint child or duplicate? Cryptic man…

Where is this “saved game instance”…i actually created a copy of the blueprint and im sure it’s wrong.
It doesnt make any sense to me to be anything else because why would it cast to itself???

They then go on to show pictures of the BP and dont say WHICH BP they are doing this in. where the pic is from and also skip the most important part out of every pic:

HOW TO START the chain! Theres a drag going out the left of the very first pic and the rest too and no picture of the whole part so I can see what “thing” is beginning it all!

Is it a custom event…a function…no event things are available to start this and they leave exactly that most absolutely important part out. cant believe it. If its a custom event…whats calling the custom event? I’m sure its not a custom event.

Yeah sorry im kinda upset right now because i wasted this entire weekend trying to get a single variable saved. and…its over and nothing has been accomplished, and I havent learned a single thing about saving a simple integer.

I feel so stupid right now. My apologies but this is driving me crazy :frowning:

So i calmed down…followed the tutorial…

  1. I am saving and loading…(print says so)…from my main menu widget buttons accordingly.
  2. I begin in a startmap that loads my main menu…then when pressing start game loads the first level. Everything is fine. I let myself die then after 2 kills.
  3. I pressed save without having a saved game. It showed my kills properly on the deathscreen.
  4. from there i got back to the main menu to SAVE that data to file
  5. when i press start game again…It says “ScoredKills existed” which means it loaded that file.
  6. If I erase that file it says that too :confused:
  7. Seemingly, there is no combination of anything i can do to get the total kills from my character to be compared to that final score…and then if larger that what was saved, replace what was saved.

FirstCharacter: KillCount (a variable on the player shown on the hud, a running toal during gameplay)
HudWidget: KillsHighScore (characters actual in game HUD and represents my highscore)
Deathscreen: KillsFinalOnDeath (supposed to be endgame total kills that should then be saved to file)
SaveGame_BP: KillsSaved (should be saved and later loaded for the highscore on the main hud)

Totalkills and totalskillsfromhud are always the same number. and i CANNOT get any of them to save to my SAVEGAME_BP’s totalsavedkills…and then on game load…put that number in my high score

My high score slot under totalkillsfromHUD remains 0

Hudwidget and deathscreen are both widgets.

on beginplay my firstcharacter is trying to load savedkills and set them to the total kills from hud

on start game frommain menu it loads the map and the saved game

You either follow that step by step tutorial I made about saving any data:

https://www.youtube.com/watch?v=6l7uynUwm5M

Or, you just make it easier for yourself, and purchase this tool from the market place, pretty cheap and save any thing within one node. And loads it with another one node!

https://www.unrealengine.com/content/fd56cc846aee471e9eb6f4496ccd24a4

-m

Well if i am being honest, yours was one of the tutorials I began to follow and quickly realised it will not work with how I want things to function. plus, If got it right you are doing something completely illogical by saving by clicking the right moiuse button and also using the level blueprint…both are completely out of the question for my game. thank you however for posting it. Your easy save and load will not work with what I am doing :frowning: I intend on having a great deal of integers saved once this initial set up is working.

for my purposes the only way to go, is the main menu UMG widget button option for saving and loading.

If someone could show me a widget to widget integer variable pass…(I am unable to castto any widget from another any other widget)…and pass a integer into a saved file… then how to load it and pass it back into the widget it came from originally…i would be forever thankful. In my head that must be a 5 minute video.

Info:
My character is able to pass to the hudwidget because my character BP opens that hud widget. if my other widget can get that number either from the character or from that widget and into my main menu widget and back into the hudwidget after loading …we are win:D

I finally got this working by creating a function that handled the loading. I created another variable in my character called highscores.

The instance of the SaveGame_BP I made wasnt even necessary and didnt function as in Mamoniems tutorial at all. I could aojnly cast first then call that…which made no sense.

If anyone wants to see the final solution dont hesistate to PM me. I am sure many coiuld use it as none of the present tutorials work.