There are a LOT of ways to do saving. Personally, I prefer the basic File commands to save my data as plaintext dictionaries. It's intuitive and easy to extend:
# Save system. Does not extend any node, but rather is
# instanced on demand to save settings or game data.
class_name SaveSystem
## Write over existing settings file with input
func save_settings(settings : Dictionary):
var save_game = File.new()
save_game.open("user://settings.save", File.WRITE)
# Store the save dictionary as a new line in the save file.
save_game.store_line(to_json(settings))
save_game.close()
## Gets game settings from local machine
func load_settings() -> Dictionary:
var load_game = File.new()
if not load_game.file_exists("user://settings.save"):
return {}
# Load the file by line and return dictionary
load_game.open("user://settings.save", File.READ)
var settings = parse_json(load_game.get_line())
load_game.close()
return settings
## Write over existing keybinds file with input
func save_keybinds(keybinds : Dictionary):
var save_game = File.new()
save_game.open("user://keybinds.save", File.WRITE)
# Store the save dictionary as a new line in the save file.
save_game.store_line(to_json(keybinds))
save_game.close()
## Gets game keybinds from local machine
func load_keybinds() -> Dictionary:
var load_keybinds = File.new()
if not load_keybinds.file_exists("user://keybinds.save"):
return {}
# Load the file by line and return dictionary
load_keybinds.open("user://keybinds.save", File.READ)
var keybinds = parse_json(load_keybinds.get_line())
load_keybinds.close()
return keybinds
## Saves game data, including progress and collectibles (GAME DEPENDENT)
func save_game():
pass
Here, I use several files for organization, but you can technically make a single dictionary with all your game's data.
The user://
path is a variable unique to GODOT and represents a system file that corrects according to OS. For windows, it's somewhere in the Appdata (see documentation).