Make_dir not available when exported

Godot Version

4.4.1

Question

func save_game(slot: int) -> void:
	var dir_access := DirAccess.open("res://")
	if !dir_access.dir_exists("save"):
		print(error_string(DirAccess.make_dir_absolute("res://save")))
	var file_world := FileAccess.open("res://save/save_%s_world.dat" % slot, FileAccess.WRITE)
	var file_player := FileAccess.open("res://save/save_%s_player.dat" % slot, FileAccess.WRITE)
	if file_world == null:
		var error_str: String = error_string(FileAccess.get_open_error())
		push_warning("Couldn't open file because: %s" % error_str)
	file_world.store_var(states_to_save)
	file_player.store_var(player_states_to_save)

This code, when runs in editor, print(error_string(DirAccess.make_dir_absolute("res://save"))) returns OK, if file_world == null: never passes.
(I used absolute path because relative path already failed.)

However, after exported, print(error_string(DirAccess.make_dir_absolute("res://save"))) returns Unavailable, then file_world failed because File not existed.

I’m on Fedora Linux KDE 42. I tried running the build with sudo…It’s more errors related to the audio, and it still prints Unavailable.

What’s causing the behaviour difference between running in editor and running a build?
Thanks for reading.

The “res://” paths are for packed files, they are read-only on exports. You should use “user://” paths to store save files.

1 Like