Loaded files are ignored in favor of current state

Godot Version

v4.7.2.stable.official

Question

When saving files, everything seems to work correctly. When loading files, the loaded information seems to be ignored in favor of the current game state. For example: 1) data is incremented to 10, 2) data is saved, 3) data is incremented again to 20, 4) data is loaded and overwrites active game state, 5) data still shows 20, not 10. What could be causing this?

“All” extends resource. It includes several sub-resources. This script simply saves the state to a default file path. By viewing “user://save00.tres” I can confirm that the file is being saved correctly. I think the problem must be with the way file is being loaded. Am I not properly overwriting the current state? Is there some way to clear cached data?

extends Node
@onready var state := All.new()
var defaultSavePath := "user://save00.tres"

func saveGame():
	state.take_over_path(defaultSavePath)
	ResourceSaver.save( state, defaultSavePath)

func loadGame():
	var newState = ResourceLoader.load( defaultSavePath )
	newState.take_over_path(defaultSavePath)
	state = null
	state = newState
	for item in state.characters:
		print( item.identity.familyName )


Some other information I have uncovered through testing:

  • This problem is not the fault of output functions. Even print() shows that the old state is not being replaced by the loaded one.
  • When the game is closed and restarted, loading DOES work correctly, and the loaded data exactly reflects the content of the file.

You’ll need to use a different CacheMode than the default one which is CACHE_MODE_REUSE. Try with CACHE_MODE_REPLACE.

Yup! That solves it! Thanks so much!