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?
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
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:
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:
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
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.
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.
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.