Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Trollend |
The problem:
I am attempting to make a Godot project that is self-contained, meaning files are both saved and written to the res:// directory rather than the user:// directory. I feel it is more simplistic to keep the files all in the same place rather than saving to the user:// directory. Despite researching it quite a bit I’m still not sure whether this is possible.
In the Godot docs on the File System, it says this about the res:// path: This file system is read-write only when running the project locally from the editor. When exported or when running on different devices (such as phones or consoles, or running from DVD), the file system will become read-only and writing will no longer be permitted.
This behavior is exactly what I am seeing, as my project can both read and write to the res:// directory within the editor but can only read and not write to the res:// directory upon exporting the project to a .exe and .pck file.
What I have now:
I ran the following code from both the editor and the exported versions.
var saveFile = File.new()
print(saveFile.file_exists("res://save_file.res"))
var err = saveFile.open("res://save_file.res", File.READ_WRITE)
print(saveFile.is_open())
print(err)
Editor output:
True
True
0 (indicating no error)
And the save file was able to be read from and written to without any issues.
Exported project output:
True
False
7 (indicating file does not exist, even when I just checked if it did exist and the output was True)
And the save file was unable to be read from or written to. If I use File.READ I can read from the file just fine. Attempting to read or write to this file when using the File.READ_WRITE method results in these errors in the debugger window:
ERROR: File must be opened before use.
At: core/bind/core_bind.cpp:1939
ERROR: File must be opened before use.
At: core/bind/core_bind.cpp:2152
Is there any way keep my project contained in the res:// directory? Also, can someone explain why it was designed to work fine in the editor but not once exported? My thanks in advance!