+1 vote

Hi all,

This code works:

func configFileSave():
    var configFile = ConfigFile.new()
    var file_to_save= "res://stats.cfg"
    var err = configFile.load(file_to_save)
    if err == OK:
        print("score written to ", file_to_save)
        print("there was an error with the file")

The problem is, for it to work on Android, I need to change the var file_to_save= "res://stats.cfg" line to var file_to_save= "user://stats.cfg"

In another game I made I had an issue where my Android build wouldn't work unless I changed it from res to user. In this game though, it's not even working with user.

Can anyone offer any advice as to why? Thanks a tonne....

in Engine by (828 points)

2 Answers

+2 votes

AFAIK, res:// is read only directory for Android.
You can't add/modify/delete in res:// which is installation directory.
If you need to save something, should use user://

by (9,768 points)

Thanks for the answer. If you look at the question above you can see I have been trying to use user but having no success. Do you by chance have any idea about why it's not working at all with user? Thanks a tonne....

+1 vote

Android is built on Linux, In linux they like to restrict permissions for a lot of the folders you need to use.

Make sure that your app has the required permissions to access the user directory.

In godot, when you try exporting to android on the 'option' side of the export dialog box. Scroll down until you reach the section for 'Permissions', check 'Read user directory'
and check 'Write user directory'
This doc page might also help: android developer documentation for declaring variables

by (124 points)
edited by

Hi and thanks for your answer. This is currently on OSX whilst I develop it, but it's still failing on anything except res. Perhaps I have to swap to user when exporting for Android, and change it back to res when exporting for OSX? Maybe that would solve it. I hadn't realised if that was the case last time. I'll check into it once I resolve another issue with Android export I'm having. Thank you.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.