How do I use "user://..." to store a file?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By P0werman1

How can I store a file to “user://…”? My code right now looks like this:

var save_file ="user://", FileAccess.WRITE)

But when I try to access it with:


It doesn’t work, even after running the program and saving. I have two ideas for why it doesn’t work, and no way to confirm or try to fix them:

  1. It won’t save files unless the project is in an exported version
  2. The web editor can’t save files (yes, I’m using the Godot web editor)

Does anyone with a better understanding of this than me have any ideas?

Have you confirmed that your script has correctly created the file? If the file doesn’t exist, then that’s why FileAccess.file_exists("user://") isn’t working. Also, when trying to access the file after it was saved, maybe using FileAccess.READ instead of FileAccess.WRITE will solve the issue?

godot_dev_ | 2023-05-05 22:28

How do I create a file? The docs I found said that opening it will automatically create it if it doesn’t exist…
Why would I be using FileAccess.READ when I am trying to overwrite the file?

P0werman1 | 2023-05-08 14:07

I am not to familiar with the file system stuff, but my intuition was that FileAccess.file_exists("user://") may require read access, and if you opened the file only for writing, then that could be the reason (just an idea, I don’t have other reasons to backup this thought)

godot_dev_ | 2023-05-08 14:27

Whenever I use FileAccess.file_exists("user://")it is before I would have accessed it any other way in the script.

P0werman1 | 2023-05-08 14:29

Okay. I think FileAccess.file_exists("user://") should be fine. What I would check then, using your file system, is whether the '' file exists. The file path will depend on your OS (e.g., in Windows, it would be somewhere like this

C:\Users<UserName>\AppData\Roaming\Godot\app_userdata<godot project name>\

If the file exists and FileAccess.file_exists("user://") is returning false, then double check that your don’t have a typo in the file name. If the file doesn’t exist, then your program is not correctly saving the file. I recommend adding print statement or a break point to the line of code where you save the file. If the statement is never reached, your program is not saving the file (check your logic). If the statement is reached, I am not sure what could be the problem

godot_dev_ | 2023-05-08 15:32

This is where I think the web editor aspect comes into play. Maybe the engine is looking for it in the normal spot, but since it’s the web editor it saves to the cache that it saves the rest of my editor data to?

P0werman1 | 2023-05-08 16:21

Indeed, it’s probably a issue caused by the web editor. Aquote from the web editor documentation “Due to browser security limitations, the editor will save the project files to the browser’s IndexedDB storage. This storage isn’t accessible as a regular folder on your machine, but is abstracted away in a database.”. So I imagine this may be the caused of the issue

godot_dev_ | 2023-05-08 16:53

Yes, that was my thoughts. Is there a way to work around this, or do I need to export to html every time I want to test it?

P0werman1 | 2023-05-08 17:02

I am not sure, sorry. You would probably save yourself trouble if you used the Godot editor instead of the web editor

godot_dev_ | 2023-05-08 17:30

I can’t lol. I’m using a school chromebook

P0werman1 | 2023-05-08 18:20