Save game state

Hi,

I’ve look at a few resources and none could clearly explain how to not only save the game which I have already implemented, but also store the state of the game world / level.

For example if the player has turned a light on in the previous session, saved the game, exited, continued from last checkpoint the light should remain on, but currently reverts to being off.

How do I make it so the game state at the time of saving is stored along with the game save?

1 Like

Yes, you have to get into a new way of thinking to do save games :slight_smile:

For the light example, it’s easiest if it’s a blueprint.

The order of action is

  1. Player turns on light
  2. Light writes its new state ( on ) to the save game
  3. Player quits game
  4. Restart the game
  5. On begin play, the light always reads the save game
  6. It sees its state was on, and switches itself on

Like that :sunglasses:

3 Likes

Hi @ClockworkOcean!

This is my blueprint for the light I have in the game, should I create a variable from the output of ‘Spawn Sound at Location’ to store the current status? if so, how would I then feed that into the Save Game?

UPDATE:
I thought this would work but it isn’t

In BP_Save Game

In Main Menu where Continue button is

Tried this as well, still not working - doing print strings tells me that True is never satisfied to print a string for some reason…

True never runs, not sure why

It’s very simple. First of all, make a function to talk to the save game, because otherwise all your blueprints become a total mess

image

In the save game, the bool

image

Then the light is just

1 Like

This issue with ‘continue button clicked’… how is that variable getting from the widget to the blueprint? I think it may be not, that’s why you’re having a problem there.

You could fiddle about to get the variable from the widget to the BP, but once you’ve got the savegame working, you can just stash it in there :slight_smile:

I’ve got myself really confused now because I think I am doubling up.

This is BP_SaveGame, which I place in the world to trigger a create save event or set as most recent save point which is called at ‘Continue Game’ button click from Main Menu.

This is also BP_SaveGame with it’s new function ‘Read Save Game’

Again, BP_SaveGame with it’s new function ‘Write Save Game’

This is Main Menu widget and ‘Continue Game’ button click logic

Put the two functions in a global function library. Not just in one BP. That way you can see those two functions from EVERYWHERE…

In the content browser

image

You never have to deal with it again :slight_smile:

1 Like

Okay that part is now done

1 Like

Ok. So any time you need the SG, that’s the way, I think it will simplify your code immensely.

You only need this once, the second rectangle is redundant

1 Like

Anywhere that there is a Save Game to Slot should I replace with Write Game Save?

Checkpoint becomes ( this is ALL the code )

( better to get the location of the player, not the checkpoint )

I’m not able to connect player pos target to Read Game Save

1 Like

Make a new node, don’t try and use the old one :slight_smile:

You need to put your save game class here

Not sure if to use the BP_SaveGame in world object or the base SaveGame?
image

Created a new variable from Get Actor Transform but it doesn’t have an option for Target?

1 Like

Your save game type ( I assume that’s BP_SaveGame? )

Pull from here and search for ‘player transform’

This is BP_SaveGame

No option

Ok, it’s not that :smiley:

You made your save game, and put the player transform variable in it. That! :slight_smile:

Also, that needs to be the type on the function also, because the function is reading and writing your save game type.

We’re talking about your save game type.

So is this correct now?

1 Like