Loading res even if file does not exist

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Andrea

Hello, i’m using the code below to load a resource (that i use as save file).
When it find a save file it loads it, when it no, it prints “no save file”

If i launch the project from debug it works correctly, but if i export the project it doesnt: sometimes, even after i delete the savefile from the folder, it loads an “old” file (i dont honestly know where does it load from)
The funny thing is it does not happens all the time: when it does, i have to re-export the project, and then it works correctly till it breaks again.

I’m not sure if this is caused by some bug in my code or some intrisic behaviour of how the resources are stored in memory?

func load_from_file():
	var file=File.new()
	if file.file_exists("res://Saves/SaveGame.res"):
		print("There is no save file")
:bust_in_silhouette: Reply From: rossunger

Have you tried using user:// instead of res:// for storing your save files? Does this have the same issue?

My understanding is when you export a game, it does some clever magic to pack all the files… It abstracts away the concept of res://, so I’m not sure how saving loading works in that context… Like, is the file appearing in your executable directory?

it works, and it looks much more stable than before, thanks for the suggestion!
As i was expecting, the answer was magic.
Dont meddle with magic kids!

Andrea | 2022-02-16 16:40