How to get .json files from 'res://' directory at exported game for Android

Godot Version

Godot 4.3 Stable Mono (C#)

Question

Hello! I’m a beginner at Godot, but I already have experience developing in Unity.
I have a question about getting a files from res:// path at exported Android game. At res://Data/Levels contains .json files for read-only. My game creates a levels based on thats .json files. But when I go to the level scene, it is not created.
I tried to find a similar problem on the forum and on the Internet but couldn’t. If you know alternative solutions to the problem, I will also be grateful.

And how can I view errors in an exported Android game?

Well a few things,

Res:// path

res:// after exporting becomes read-only, means you cannot modify it. just seen the edit you made

Can’t see the .json file

For that make sure that when youre exporting you include that you want to export the .json file, like so:

How to view errors in an exported Android Game?

As far as i am aware, you can’t.

Tho there is a option to connect your android device to debug the game directly on your android phone, with debug printing in the editor.
Look into One-click deploy doc to see how to do it properly

Hope this will help you :3

1 Like

Thanks for help, @galfar.

About res://: I tried adding it to the filter .json, but the level still doesn’t start. Everything is complicated by the fact that I can’t see the errors to understand what exactly the problem is.
My code with problem:

string levelsFilesPath = OS.HasFeature("editor") 
					    ? ProjectSettings.GlobalizePath("res://Data/Levels")
					    : OS.GetExecutablePath().GetBaseDir().PathJoin("Data/Levels");

About One-click deploy: I has already make that, but debug prints not show at editor.

First thing

Don’t Globalize res://Data/Levels, Godot recognizes this as its own directory inside the app itself (best explanation i got).

Second thing

Same goes for OS.GetExecutablePath().GetBaseDir().PathJoin("Data/Levels")

I am pretty sure that even GDScript and C#, godot handles both the same way, as far as i am aware.

Extra

So if you have all your levels stored in res://Data/levels they should be accesible by just getting the path as marked, without Globalizing it. Godot will handle that internally.

Also, for the One-click deploy, it might not show because there are various settings when exporting, to export with or without debug.

also just to mention, but you should know that Godot itself says:
Godot_v4.3-stable_mono_win64_PYPGZYk6za

But in your case, it should only be the way you’re accessing the res:// path

let me know if you need more explanation or help :3

1 Like

Unfortunately, without ProjectSettings.GlobalizePath() it doesn’t work even in the editor, because this path is passed to the File.ReadAllText(filePath) from the library System.IO. Is it possible to get .json files without using the standard File class?
For debug I place RichTextLabel and write he’s Text property. It indicates that the level file was not read.

Well, I am not very well experienced in Godot’s C# as i was mainly a unity dev before moving to godot and decided to settle on GDScript instead of C#.

But after some digging i found a post answer that could possible guide you in the right way:

if you modify this so it works with your code, in theory it should work. but as i said i have almost 0 experience with Godot’s C#

edit: And yes this uses Godot’s File, which should be how you open res:// or user:// path’s which Godot interally handles.

1 Like

Yeah, that’s work. Thanks you so much, @galfar.
I adaptive my code with using Godot FileAccess for get .json files and ResourceLoader.Exists(objectFilePath, "PackedScene") for check .tscn exist for level objects instead of File.Exist().

Conclusion: don’t use the standard ones System.IO classes for working with Godot files. Instead, use the FileAccess class built into Godot, which allows you to use res:// when specifying file paths.

1 Like

Additional details:
I found a way to enable USB debugging so that the print function (GD.Print() method) outputs messages from the phone to the Godot editor console for C# (tested on Godot 4.3 Stable Mono).
To do this, simply enable Debug - > Deploy with Remote Debugging in the engine top menu.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.