The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I learned how to create a save file using json

It worked well when I ran it on my pc.

But it does not work on Android

If godot does not have a json file, it will generate a json file the first time it runs

But if you change the contents and keep the json file name, it does not seem to be updated

So I thought that every run would not detect, update, or generate changes in the json file

I think we only create a new json file when it does not exist.

But on Android, no save is applied

I'm wondering if the json file is being created, but I do not know where the folder of the app I installed is

in Engine by (36 points)

Hello sir, I am experiencing the same problem with saved file on android cannot be found. Did you perhaps already have a solution for this?

1 Answer

0 votes
Best answer

Can you post the code that creates the JSON file?

by (294 points)
selected by
var save_dictionary = {
"easy_high_score" : 0,
"nomal_high_score" : 0,
"music" : true,
"sfx" : true
}

const save_path = "res://save/save.json"

func load_data():
var save_file = File.new()
if save_file.file_exists(save_path) == true:
    save_file.open(save_path, File.READ)
    var json_string = save_file.get_line()
    save_file.close()
    save_dictionary = parse_json(json_string)
else:
    print("no save")

func save_data():
var json_string = to_json(global.save_dictionary)
var save_file = File.new()
save_file.open(global.save_path, File.WRITE)
save_file.store_line(json_string)
save_file.close()

In this state, the load_data function is executed in the title scene
If the json file does not exist, it is created

res:// is no valid save path IMHO. This directory is read only on some platforms including android. (comparable to "Program Files" in Windows).

Save and load your data to/from user:// instead.

Oh I see

I tested it on my pc before exporting it to Android, but I do not know where it is stored on my pc

I can not see the folder or file related to save when I go to 'Drive C - User'

I found out where it was stored.

But I put the folder name in front of the file name, but I did not create the folder

So I deleted the folder name part and the file was created

But I do not know where Android is generated.

Even if you search the internet, all the answers have only links to the wrong posts

Android allows only file writes for apps to user://. And, if you enable the access right for it, they can also read/write in public "SD-Card" space. (Unless you use a rooted device.)

Android expects apps to write their "private" data into user://. This data can not be read or written by other apps.

You can create folders in user://, no problem. The operating system decides where the path is. Normally you don't have to bother. In Windows 10 for example, you find these files under: C:\Users\<MyUserName>\AppData\Roaming\Godot\app_userdata\<MyProjectName>

So how do I access the user: // file on Android?

Do I have to connect to my pc and find the file on my pc?

I will use a method to clear the file and recreate it to make sure that the changes in the values are applied correctly

To do so, I need to be able to access the file

user:// is a whole path. So you can save your file under that path like you tried with res://

const save_path = "user://save.json"

You can access that file from your app.
You can delete that file from your app. If you want to know the contents then you can read it into a variable and dump the output with print(variable) while debugging it.

Directory offers some methods dealing with files. You can delete files or create directories as you like.
https://docs.godotengine.org/en/3.1/classes/class_directory.html

On Android, all files in the user:// path will be deleted when you uninstall an app. (But not on updates)
So the easiest way to delete android files in user:// which you ie.e. created during testing is to simply uninstall the app.

Right. I'll have to test it by deleting the app and reinstalling it. Thank you very much !

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.