Native class "FileAccess" cannot be constructed as it is abstract

Godot Version

4.2.2

Hi everyone,

this is in my file-manager:

extends Node

const file_name = "app-data.data"
const file_path = "user://" + file_name

func load_data():
	var file = File.new()
	if not file.file_exists(file_path):
		print_debug('file [%s] does not exist; creating' % file_path)
		save_data()

Switching from Godot 3.5.3 to 4.2.2, an error at exporting my project occurs:
Identifier "File" not declared in the current scope.
I know something changed by the current version and I see “FileAccess” in the docs… but changing File to FileAccess gives me the message: “Native class "FileAccess" cannot be constructed as it is abstract.

I’m at a loss here. Could this be solved without drastically change the existing code?

Use FileAccess.open instead of File.new()

2 Likes

That’s it, thanks!

1 Like