I have been working on a saving and loading system and got one to work fully. However, it only saves the player location and actor location (such as cubes, spheres, etc.). I need it to also save player variables such as current ammo, health, hunger, etc. Here is the current setup in blueprints:
Looks like you know how to do everything, you just need to do the same thing with your other information. Add the variables you need to save to your save BP and set them like you are setting the locations above. Is there something specific that’s keeping you from doing that?
I have already set my variables in the save BP. The problem is that I’m not sure where to set my variables in the save and load system. It seems like the way the location is set is completely different from just doing normal variables. Would you be able to throw something together real quick and provide a screenshot for me? Or just explain where I would need to set the variables and tell me where the return values would go.
It’s not really. It’s just a more advanced use-case- the method for saving/loading the value doesn’t change, only you’re already doing what you need to with that information. If you need to store, for example, the player’s health in a save then create a variable for player health in the savegame, and store that variable in the savegame when saving, and get that variable from the savegame when loading. Then, say you have a material that changes based on the player’s remaining health, you’d have to give it the correct health value. In a similar way, when you load an actor transform you may as well go ahead and update it’s transform in the world.
The save game object acts as a sort of protocol for loading/saving specific data. You have to go add the variables you want to save/load in the SaveGame Blueprint, but then everytime you save, you must pass in values (in a way) and everytime you load you’ll have to do stuff with the data. What data and when you save/load are up to you, the designer.
The tools and workflow for the ‘protocol’ are always the same- regardless of variable type.
To prep a variable for saving, get a valid save game object (of your type), and drag the reference pin out and release for the context menu. Type “Set <VarName>”, and select the correct option from that menu. Connect it along the execution line, and set the variable to the value you want to save, and once you’ve done that for each value you want to save, call Save Game To Slot for the savegame you’ve been using, and make sure the slot is unique to that save’s purpose (If you have multiple players, you don’t want Player 1 and Player 2 to overwrite each other’s saves).
To load a variable from disk, get a valid save game object, drag the reference out- This time type “Get <VarName>”- and the variable you’ll be using for the rest of runtime should be set to the value you get from the get node. Do this for every value you want to load.
Sorry if I came of too patronizing, I just wanted to break it down very simply.
Are you testing the Hunger variable at all? Try printing the value to screen and/or saving it to a variable. In this case, right click anywhere and type “Set Hunger” and it should bring up your Hunger variable used in the first screenshot. You’ll need to connect the SaveGame’s Hunger to the Set Hunger node.
Thank you for providing the screenshot. It was very helpful. As well as the deep explanation. I was able to successfully save all my data such as hunger, health, ammo, etc. Thank you for your continuous help! Have a nice day