Reading Files from Disk in Godot 4 with FileAccess

preview_player
Показать описание
When making games Godot where data comes from outside of main engine editor, you'll often want to be able to read files and utilize what's within them. You can easily read JSON, plain text, and more in GDScript. This video covers how to read text from a file and put it in a Label node.

This video is focused on reading text from res (Resource) space. An upcoming video will handle reading from user space with player save game data.

Godot version used: 4.0

#GodotEngine #Godot #GodotQuickTip #Godot4
Рекомендации по теме
Комментарии
Автор

Never thought I have that Cmd + D or Ctrl + D power in my hand. Didn't know that Godot already have that. Thanks

meow
Автор

so useful thank you!! I especially like in windows just holding ctrl and clicking on functions to see what they are

bonsaipropaganda
Автор

Thanks. This was exactly what I was looking for.

eewee
Автор

it's good to know how to do this, but unless you already have existing json data from an external source, i would strongly recommend using godot custom resources to save player data, high scores, etc. also, your project won't actually include json files by default, so when you export your game it's going to stop working until you fix that in the export process.

furroy
Автор

Which format is best for Map Data? or is it better to make it yourself with custom reader? Im new to all this file-to-file transfering, reading and writing so i just dont know what to use.

the-guy-beyond-the-socket
Автор

Greetings, I'm new to Godot, I'm using 4.0. Is it possible to read and write to file types like odt, docx and similar? Since when I try to open file.odt, I only get "PK" displayed in the print console, even though I know that is not what is written in there. Anybody else have the same issue?

eternal_learner
Автор

Can I somehow access only specific Lines/Text from a File?

holtsdav-yt
Автор

The issue I change the scene and file becomes empty even with Global variable. Text must be stored, right? I want new scene coz I will edit the file (search letters) and show compilation, no need to display full file.

blandon
Автор

Yo. How can I get the characteristics of objects? For example, in the text file:
ironSword {

damage = 10
}
help me, please

diobrando
Автор

if you run on browser or Android, Godot can't read from "res:"

danielemanna
Автор

Him read only string text or we can convert numerical value ?

darkhunter
Автор

how do we write and overwrite to the file though?

bonsaipropaganda
Автор

IN GODOT 4.2 don t work and
func _ready():
var file = File.new()
if
print(" No saved! ")
return
too don t work 🤣

darkhunter