How to check if a scene exists?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DarlesLSF

Hello all again, I want to check if a certain scene exist. How can I do that?

:bust_in_silhouette: Reply From: kidscancode

You can check if a file exists using:
https://docs.godotengine.org/en/latest/classes/class_file.html#class-file-method-file-exists

You can also see examples of how to use the File object farther up that page.

:bust_in_silhouette: Reply From: luislodosm

For example:

export(String, FILE, "*.tscn") var path_to_scene

func change_scene():
	if ResourceLoader.exists(path_to_scene):
		var _error = get_tree().change_scene(path_to_scene)