Save/Load Functionality


The following is part of a bi-weekly update we would be required to do as we worked on our final projects. Some things may require context that is not included or some original post content may be excluded.


Last week I worked on the ability to save the game. I had something set up initially for when I did eventually implement it, but when it actually came to testing it, it didn't work like how I wanted it.

This meant I had to go figure out a different way to save the game. After a bit of searching online, I came across this tutorial by a YouTube channel called Godotneers that explained ways to save a game in Godot.

I watched the video on Thursday with the remaining of my time, and then actually worked on reworking my save system based on the video on Friday. I thought it was going to be difficult as I had developed the project for a while without preparing it for the kind of save system the video showed, but to my surprise, it was easier to implement than I expected.


The save_player_data and load_player_data functions that take in a SavedGame object, based on the Godotneers video.

The save system worked pretty well when I first tested it, with a few minor issues. Some of those was just more properties I had to save or some semantic/syntax issue.


The save_game function that is based on the one made in the Godotneer video, but altered to fit my game's structure.

The biggest issue I came across was reloading into save files. When I saved a game and returned to it, changed something, left and then returned to it again, it would load the save before it. I was wondering why this was the case as the results that showed up when researching this kind of issue was that the ResourceSaver should be overwriting the previous file.

It turned out the fault was with the ResourceLoader. When loading a file, by default, the ResourceLoader will keep that file in a cache and derive from it when the resource is asked to be loaded again. So what I did to resolve this was to set the cache flags in the load function to ignore caching the loaded file.


The request_save_file function that uses ResourceLoader's load_threaded_request function. The last parameter is the enum that determines how the loaded file is cached.

This fixed the issue with reloading files and now the game will always load with the newest version of the save file.

What I want to work on going forward is to finish up the save system and then add the background music my friend made for the game.

Get ECO-Keeper