Game Development | Save And Load

in Game Development2 months ago

loadgame variables.jpg

Kind of silly I have not had much of anything set up for saving the game in quite some time. You might have noticed in the early days I had a slowly increasing amount of experience and gold as I progressed through working on the game and taking screenshots. After some time I made changes and my old save system was no longer working.

In Unreal Engine 4 (UE4) setting up a single-player save is quite simple. This will need to be expanded one day for when I start doing more server work. For the short-term testing, I needed something in place. Something that I could quickly save and reload with a press of a key button without anything fancy.

Savegame blueprint variables.png

UE4 has a special kind of blueprint class called SaveGame. In that blueprint, you just need to create all the variables you want to save. This is everything from the gold and experience amount the player has to equipment and anything else.

Next, you just need to go to the blueprint that has the actual variables that you are wanting to save. For now, that is my ThirdPersonCharacter blueprint. That is where the rest of the saving game part will take place in this simple example.

Since I’m not setting up anything from a UI standpoint of clicking a button to save or load a game. I just used two keys I’m not using for anything else. Which for me are going to be the P and L keys. While I might at a later date put more time into this for testing in the months ahead. It’s not needed and one day the I’ll be having a server save every so often so a lot of this is just a temporary fix for now till I work all that out.

blueprint for savegame.png

The first major component is saving the actual game. For that, you need how you are going to trigger the event which in my case is the keypress of P. Next up skipping the switch I have for authority since I am running a server. You need a Create Save Game Object that is set to your save game file which in my case is called MySavegame.

Next, I need to pull all the variables I had put in the MySavegame blueprint. I set them all to the variables in the ThridPersonCharacter where they were being used. Finishing with a Save Game to Slot with a name I wanted to call the save. Maybe I’ll get fancy later on and have a couple of them set up for switching between different classes for testing.

loadgame variables.png
After that, it was time to set something up for loading the save. I ended up using the keypress of L for the load. Then you just needed to Load the Game from Slot naming the slot name you wanted to load. You then cast it to the name of your save game blueprint and as that blueprint all the variables you have in it. After that, you need to set all the variables you are using in ThridPersonCharacter.

Once that all was all done it was time to do some quick testing. Everything seems to check out and this will be moved over to my main project file during the week along with some other things I’ve been working on.

Final Thoughts

That is it. Quite simple and basic. I have a couple more variables I need to add to make sure everything I want to be saved gets saved once I move things over. This is something I should have redone quite a long time ago and to the degree I just did. Think it took me longer to write this post than to set it up.

I’m in the middle of redoing a lot of things. Polishing up other things and lots of testing. This is just one of those things I needed to sit down for 10 minutes or so and set up. Seems I have an endless amount of these little basic tasks that I have been putting off for way too long that I’ll be getting around to doing soon enough.

Other Posts:

Information

Screenshots were taken and content was written by @Enjar. Screenshots are from Unreal Engine 4.

Game roadmap.

Sort:  

Only weaklings that die need the save function ;)

!LUV

Lol, I don't recommend trying to do all 25 zones in one sitting without taking a break. A save or two might be needed.

Hi @enjar, you were just shared some LUV thanks to @dksart. Having at least 5 LUV in your wallet enables you to give up to 3 LUV per day, for free. See the LUV tokens in your wallet at https://hive-engine.com or learn about LUV at https://peakd.com/@luvshares

Twitter.