ResourceSaver.save() not creating file

Godot Version

4.7.1 stable Windows 11

Question

So this is my global script that is supposed to manage save files:

extends Node

var save_path : String = OS.get_user_data_dir() + "/savedata/savefile.tres"
var save_info : SaveGame = null

func _ready() -> void:
	print("save path: ", save_path)
	if ResourceLoader.exists(save_path):
		print("save path exists")
		load_data()
	else:
		print("save path does not exist")
		save_info = SaveGame.new()
		save_data()

func load_data() -> void :
	save_info = ResourceLoader.load(save_path, "", ResourceLoader.CACHE_MODE_IGNORE)
	print("when loading: ", save_info.INPUTS)
	update_language()

func save_data() -> void :
	ResourceSaver.save(save_info, save_path)
	print("when saving: ", save_info.INPUTS)
	update_language()

SaveGame is a class that holds all the values that are supposed to get saved and loaded, and every variable in it is an @export.

But ResourceSaver.save(save_info, save_path) does not create a file when it executes, as is visible when I go to the directory that I can find with print("save path: ", save_path). Everytime I run my game, it prints save path does not exist.

I was originally using json files and FileAccess.write() for saving my game, and I was experiencing the same problem of no save file being created, but I switched to using a resource instead in hopes it would fix it, and it didn’t. What could be the cause and solution? Any help is appreciated.

You have to create savedata folder first.

I don’t know how to do that but I’m sure you can find it online easily.

Or just save it under the main user data dir without savedata folder

Note: I’d also recommend this, instead of OS.get_user_data_dir()

const SAVE_PATH := “user://savefile.tres”