Only save game once on open level

hi,

i want to create an ‘initial save’ when the level opens that only runs once that…well saves that game once initially as soon as the level is loaded

in my thirdpersonmap blueprint, i have the following attached to the eventbeginplay node

this should be checking against the thirdpersongamemode for a variable called ‘LocalInitialSave’ and if it is set to FALSE, it will set it TRUE and then Save the game

here is the thirdpersongamemode nodes for loading the game

here is the thirdpersongamemode nodes for saving the game

the idea is that…

  1. open level = check if initial save variable is TRUE, if not, set it to TRUE and SAVE the game
  2. thirdpersongamemode receives word that ‘LocalInitialSave’ should be TRUE, so it does that from the level blueprint
  3. thirdpersongamemode receives word that it should SAVE, so it captures ‘LocalInitialSave’ is TRUE and sets that same value to the Save Game blueprint to persist
  4. when the player plays the game again, it should see the ‘InitialSave’ is already done so it can safely skip it

Issue is it keeps saving each and every time, nowhere else am I saving the game

1 Like

The game mode gets replaced when you load levels ( assuming you’re using open level ).

Best way to do this is use the save game entirely, so especially for the ‘has the level saved’ bool :slight_smile:

Also, in this section

You are making the new save game, but not setting the variable before saving it.

1 Like

thanks, i’m still a little lost sorry

so in the map itself i change it to the following?

within the save function of the gamemode, i set the initial save bool in the game save file, instead of using the local variable

then for load game i’m not sure what to do, have i done it right so far?

1 Like

I think this is the main problem

If you already have a save game, you load/set/save.

But if you make a new one, you just make/save/save again. Also you’re writing out nothing at the end, because the save game ref is not valid. I assume if you clear the save game and try you get ‘none’ errors?

Is the variable set to true in the default save game?

the ‘InitialSave’ is set to false in the savegame bp

so am i to get rid of these two? if so how do i reference it in the ‘Save Game to Slot’ without the cast?

1 Like

This is what you’re heading for, I think

:slight_smile:

it still saves each time I open the level again

1 Like

I don’t know if saving from a ‘set’ that you didn’t use will work. Can you try actually using the variable?

drawing a blank, i’m not sure what variable i am pulling from where, it’s only the playersave bp variable that exists now

1 Like

Look at what I have?

:slight_smile:

I’m not sure if this is it, but good to check.

hasn’t changed yet but I’ve made mine more like yours

1 Like

I’ll give you a level BP that will tell you if the level has loaded or not previously, and you can decide where you want to put the code? This works, although it’s kinda redundant to have a variable, because if the save game is there, then we have loaded before

i should have provided more context for this i’m sorry

when the player dies, i want a text render to go up by 1 and i would like the number to accumulate despite opening the level again after death

  1. player overlaps something that kills them then it runs a custom node called ‘Update Death Count’ which does the code above

  1. the update death count bp itself should be add 1 to the text render 0, 1, 2 etc then saves that value to the game mode and then the save file for storage

  2. the player clicks ‘Retry’ then the level opens again and loads in the value for the text render that is checked when the player is dead again as code above

1 Like

Ah, now we’re cooking

1 Like

significant progress made! only issue left is that it starts at 1 death for some reason :joy:

oh it will be this for sure within the death text render itself, how should i clean this up

1 Like

Just do the text before you increment the count :slight_smile:

i’m making it worse again haha!

the string says i already died 1 time on first spawn after deleting save, then after i respawn it says I’ve died 3 times

1 Like

Well, you get the idea :slight_smile:

You’re setting it before drawing the widget, or something…

i think it’s this? on event being play of the level map it adds one without any sort of condition, so it always starts at 1

actually no, this extra save call seems to be calling the issue

fixed result, thank you, you absolute mastermind, i deeply appreciate you

1 Like

Awsome :star_struck:

1 Like