I'm trying to save some variable to a file. I used .dat file but Godot didn't import it in the project files. So upon export, it just didn't work. I tried .txt format, and Godot does import it, but I have to add *.txt to Resources upon exporting the project. I want my module to work without the need to change any settings...

So I tried .res file. But every time I open the project, it says:

"Unrecognized binary resource file: res://Sender-Receiver System/sender_list.res."

However it does import it, and it does work perfectly, even in the exported project.

I suppose the reason for the error is that I'm using the FileAccess. Here's the code:

var path = get_script().get_path().get_base_dir()+"/sender_list.res"
var file = FileAccess.open(path, FileAccess.WRITE)
file.store_var(SenderList)
file.close()

SenderList is an array.

What am I supposed to do? The .res file DOES work, but gives that nasty error. The other file formats need to manually be added to the list of files upon exporting the project.

I want to be able to use my system by just dragging and dropping the folder, wihout the need for additional changes in the settings...

  • xyz replied to this.
  • while-free- I'd always opt for a resource class even if it's a single variable. However a simple binary file with store_var()/get_var() is ok as well. Just don't treat is as engine's standard resource file because it isn't. In your case the *.res extension may be misleading the engine into trying to interpret it as such.

    while-free- instead of FileAcces::store_var() on a binary file it would be much easier to keep your variables in a custom Resource derived class and just store/retrieve the resource object as needed. That's what resource objects are designed for after all.

      xyz As it's just one single variable used in a system, I prefer not to add a new class. I kinda feel it's overkill or something (or maybe I have a sick mind xD)

      If I use "user://" instead of "res://" it works fine on any file format. However the variable is not supposed to be changed at runtime, hence I decided to put it in the res directory.

      So is there any workaround to do it with the FileAccess or do I have to use custom resources?

      • xyz replied to this.

        while-free- I'd always opt for a resource class even if it's a single variable. However a simple binary file with store_var()/get_var() is ok as well. Just don't treat is as engine's standard resource file because it isn't. In your case the *.res extension may be misleading the engine into trying to interpret it as such.