How to get text from res:// txt file in exported project?

Godot Version

4.4.1

Question

Hello! In my game I have txt files which are copied into user:// to make it so players can edit them! These txt files are lines of text used to randomize dialog in the game.

(The which file var is made so it only creates the files it doesn’t detect)

The problem arises (only in an exported project) when it checks that the game is opened and the files aren’t there so it needs to copy the files from res:// to user://, it can’t access the file. Some people who have tested the game have reported that it prints "<null>" on all the files it creates.
I have created error messages to inform the players that the files are not how they are supposed to be and such, but I haven’t figured out a work around to accessing the file. Any help?

Did you include *.txt files in the export settings, under “Resources”?

+1 about the *.txt include.

Also, you should be informed about this part of the documentation:

Keep in mind that file names may change or be remapped after export. If you want to see the actual resource file list as it appears in the editor, use ResourceLoader.list_directory() instead.

In practice, that means some files will a different path than the one they have in editor. For instance, some files have a .remap extension added, which you should consider if loading text file by name.
I did export my own game recently and I had trouble with that for .xml files (which are essentially just text but I had to include them manually). Other extensions (like .tres, .tscn and so on) worked fine.

1 Like