Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot can't load CSV file as TextFile resource #38245

Closed
henriquelalves opened this issue Apr 27, 2020 · 25 comments
Closed

Godot can't load CSV file as TextFile resource #38245

henriquelalves opened this issue Apr 27, 2020 · 25 comments

Comments

@henriquelalves
Copy link
Contributor

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

@Xrayez
Copy link
Contributor

Xrayez commented Apr 27, 2020

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

@willnationsdev
Copy link
Contributor

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.

@henriquelalves
Copy link
Contributor Author

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

@willnationsdev
Copy link
Contributor

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.

@henriquelalves
Copy link
Contributor Author

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?

@willnationsdev
Copy link
Contributor

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

@golddotasksquestions
Copy link

golddotasksquestions commented Apr 28, 2020

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])

@Calinou
Copy link
Member

Calinou commented Apr 28, 2020

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.

@Paulb23
Copy link
Member

Paulb23 commented Apr 28, 2020

See #36297

@YLL
Copy link

YLL commented May 12, 2020

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.

@willnationsdev
Copy link
Contributor

@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.

@golddotasksquestions
Copy link

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.

@henricazottes
Copy link

I can parse csv files with file.open("res://path/to/file.csv") with no problem but I have an error in the editor stating:

 editor/import/resource_importer_csv_translation.cpp:96 - Condition "line.size() <= 1" is true. Returned: ERR_PARSE_ERROR
 editor/editor_file_system.cpp:1801 - Error importing 'res://data/input/booster_profile/F15_TC.csv'.

@Calinou
Copy link
Member

Calinou commented Dec 2, 2020

@henricazottes Select the CSV file in the FileSystem dock, go to the Import dock, change the import type from Translation to CSV then click Reimport.

@henricazottes
Copy link

Thanks @Calinou , now I have this error when I double click on it:

 Failed loading resource: res://data/input/booster_profile/F15_TC.csv. Make sure resources have been imported by opening the project in the editor at least once.
 editor/editor_node.cpp:854 - Condition "!res.is_valid()" is true. Returned: ERR_CANT_OPEN

Is it supposed to display the data / be editable ?

@Calinou
Copy link
Member

Calinou commented Dec 2, 2020

Is it supposed to display the data / be editable ?

No, Godot doesn't have a built-in CSV editor.

Out of curiosity, can you upload the CSV file here (in a ZIP archive)? Make sure it's UTF-8 encoded without BOM. Microsoft Excel will create incorrectly encoded CSV files; use LibreOffice Calc or Google Sheets instead.

@henricazottes
Copy link

henricazottes commented Dec 2, 2020

So the error above is normal?

Here you go (.txt for github to accept the file). I'm using libreoffice, with ; separated values.
F15_TC.csv.txt

@Calinou
Copy link
Member

Calinou commented Dec 2, 2020

So the error above is normal?

Yes, I think it's expected since importing it as a pure CSV file will make sure Godot doesn't treat it as a translation during the exporting process.

@akien-mga
Copy link
Member

The no-op "CSV" importer is removed by #47301 as it's superseded by #47268 - you can now configure .csv files not to be imported at all, so you can parse them from script, and they will still be properly exported.

This doesn't allow actually editing the CSV files in the GDScript editor, but this issue seems to have mostly comments related to the workflow of avoiding CSV files from being used as translations, which is now properly fixed. The whole TextFile business is quite limited in its current implementation (see #36297), and the needs for manual editing of CSV in the editor might be better served by godotengine/godot-proposals#13.

@akien-mga akien-mga added this to the 4.0 milestone Mar 24, 2021
@PyramidHead01
Copy link

Hello, I am having the same problem in godot 4 and I not found another post with this issue.

I can work with the csv files, the only problem is than upset me the 2 error lines for every csv file, even changed to UTF-8 and not worked and if I go to import window I can't interact with they.

The txt works fine and delete the problem, but I want to have a few CSV, and I would like not change the file type every moment.

I am new in godot and there is so many thing than I don't understand, I assume than there is a problem created just by me.

@ultrasuperpingu
Copy link

I still get this error in 4.3.dev5.mono:
editor/import/resource_importer_csv_translation.cpp:95 - Condition "line.size() <= 1" is true. Returning: ERR_PARSE_ERROR Error importing 'res://test/test.csv'.

And the Import dock show nothing. Is it normal ? Am I missing something ?

@pozitiffcat
Copy link

Godot 4.2.1. stable
editor/import/resource_importer_csv_translation.cpp:95 - Condition "line.size() <= 1" is true. Returning: ERR_PARSE_ERROR
Error importing 'res://Text.csv'.

Can't import any csv
for example:

keys;en
fsafsd;fsfsdaf

@Calinou
Copy link
Member

Calinou commented Mar 29, 2024

@pozitiffcat If your CSV uses semicolons as separators, you need to change the separator to Semicolon (;) in the Import dock for the CSV file. The default separator is Comma (,).

Also, make sure the CSV file is UTF-8 encoded without BOM. Microsoft Excel will create incorrectly encoded CSV files; use LibreOffice Calc or Google Sheets instead.

@ultrasuperpingu
Copy link

ultrasuperpingu commented Mar 29, 2024

If your file does not use a comma separator (or have any other problem making the translation importer fail) when you're importing it, the Import dock will not shows up (see #82002). I had this problem, the only way out I found is to make the file a "valid csv" (like a file with content:",\n"), changed its import options, and changed the csv back.

Hope this helps :)

@pozitiffcat
Copy link

If your file does not use a comma separator (or have any other problem making the translation importer fail) when you're importing it, the Import dock will not shows up (see #82002). I had this problem, the only way out I found is to make the file a "valid csv" (like a file with content:",\n"), changed its import options, and changed the csv back.

Hope this helps :)

It helped me. Not able to import CSV first time with semicolon separator. Import settings is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests