Godot Version
4.3
Question
I’m having an issue with my save system. I have it saving to a file, then loading from a file. Just trying to keep it basic as it’s my first save system.
This is my player manager when I do hit my save button the print statements show correctly and should be saved to the file. However when loading the game. It prints out nothing for the location and 0,0 for the position.
Edit: Does it matter if it’s being run from the engine for testing? Does it wipe user:// in-between runs?
#--------------
#Player Manager
#--------------
extends Node
var player_data: PlayerData = PlayerData.new()
func save_game() -> void:
var error = ResourceSaver.save(player_data, "user://player_data.tres")
if error != OK:
print("Failed to save game: ", error)
print(player_data)
print(player_data.location)
print(player_data.position)
func load_game() -> void:
if ResourceLoader.exists("user://player_data.tres"):
player_data = ResourceLoader.load("user://player_data.tres")
print("Loading player data")
print(player_data)
print(player_data.location)
print(player_data.position)
else:
print("No saved game found.")
This is the code for my load button that is on the title screen:
#Load a previous game
func _on_btn_load_pressed() -> void:
SaveManager.load_game() #Load saved data
var player_data = PlayerManager.player_data #Get a copy of the player data
if player_data: #If there is player data
SceneManager.change_scene(self, player_data.location, true)
await SceneManager.scene_transition_finished
else:
print("No saved game found.")
This is my save manager, I created it for future growth though right now it just straight passes to the player save:
func save_game() -> void:
PlayerManager.save_game()
func load_game() -> void:
PlayerManager.load_game()