Godot: Godot can't load CSV file as TextFile resource

Created on 27 Apr 2020  路  12Comments  路  Source: godotengine/godot

Godot version: 3.2.1 (Stable)

OS/device including version: Manjaro

Issue description: Godot doesn't seems to be able to load non-localization CSV files in the editor. Trying to load it in any export(Resource) var or export(TextFile) var gives:

ERROR: _load: Failed loading resource: res://test.csv.
   At: core/io/resource_loader.cpp:278.

and clicking it twice gives:

ERROR: load_resource: Condition "!res.is_valid()" is true. Returned: ERR_CANT_OPEN
   At: editor/editor_node.cpp:735.

Not sure if it is related, but are .txt files supposed to be hidden in Editor? Trying to change a .csv file to .txt makes it impossible to be selected as a file in the inspector.

Steps to reproduce: Any .CSV file in the project (imported as a normal CSV file, not localization) should be able to reproduce this.

Minimal reproduction project: Annexed to the issue.
csv-problem.tar.gz

discussion import

Most helpful comment

That's weird because there is a 'normal' CSV importing option on the file itself, along with the 'Localization CSV' option. If it can't be imported as a regular resource, what is its purpose? Should I be able to import non-resource, non-object files to the project?

All 12 comments

CC @willnationsdev as he worked on some CSV related import stuff.

Afaik, the TextFile class only has usability from the editor itself (there's no API exposed for working with it). You can only open a TextFile directly in the ScriptEditor and save it. I don't think it works when you try to export it as a property, but I haven't really tried much.

@willnationsdev I see. But CSV files are not being loaded even as normal resources; is this normal?

As I understand it, *.csv files are imported and translation resources are generated from configuring the .csv's use in the Localization part of the ProjectSettings. So, yeah, the .csv files are not, strictly speaking, the "source" of the Translation resource object instance. They aren't like regular resources.

That's weird because there is a 'normal' CSV importing option on the file itself, along with the 'Localization CSV' option. If it can't be imported as a regular resource, what is its purpose? Should I be able to import non-resource, non-object files to the project?

@henriquelalves Not sure. Maybe I'm misunderstanding something about it. Would have to check back through the source code.

The workaround is to rename your yourfile.csv file to yourfile.csv.txt
This is really annoying though, and I really wish Godot would change the automated "import as translation" as soon as possible.

example code:

var file = File.new()
file.open("res://yourfile.csv.txt", file.READ)
while !file.eof_reached():
    var csv_rows = file.get_csv_line("\t") # I use tab as delimiter
    csv.append(csv_rows)
file.close()
csv.pop_back() #remove last empty array get_csv_line() has created 
headers = Array(csv[0])

I suppose we should change the file extension for translation CSVs to something else. This would require people exporting CSVs from LibreOffice to rename the extension manually though.

See #36297

Same here. The CSV import option makes it unable to load the file in any exported game.

Moreover, if I RENAME the .csv file which imported as CSV in the filesystem dock to .txt file, the .csv.import file created by the editor will NOT be deleted, it's just renamed to .txt.import and the content is untouched leaving something like:

[dep]

source_file="res://xxx.csv"

That makes the .txt file NOT packing into any export.
Don't know whether I should post this here or make a new issue.

@YLL I feel like the import issue is a slightly different problem that should have its own bug issue. If the same PR can fix both problems at once, then great, but otherwise, you wouldn't want to close this Issue if only one part of the problem was resolved. If you make a bug Issue, make sure to mention this one so that people know they're related.

Does anyone still have this issue in 3.2.3 stable and 3.2.4? I can load and parse file.csv as textfiles now without problems without the file.csv.txt renaming workaround.

Was this page helpful?
0 / 5 - 0 ratings