Load a scene outside of res

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rolfpancake
:warning: Old Version Published before Godot 3 was released.

I am using the Directory class to search for files outside of the projects res-folder and it is working fine. However I am not able to load a scene which path is outside of the res-folder. Is this even possible?

Works:

var scene = load("res://scene.tscn") 

Doesn’t work:

var scene = load("../scene.tscn") 
var scene = load("C:/scene.tscn") 
:bust_in_silhouette: Reply From: literalcitrus

Use ResourceLoader.load() instead of load().

var scene = ResourceLoader.load("../scene.tscn")

Works with both .tscn and .scn scene files (and any other file that can be loaded as a Resource in Godot).

Just keep in mind that some systems will not allow Godot to do that.

eons | 2018-01-16 16:15

Works like a charm, thank you!
@eons: Which systems will prohibit that and can it be circumvented?

I also want to add that it is possible that you get an error message like this, when loading from a different path:

ERROR: ResourceInteractiveLoaderText::poll: res://../scene.tscn:3 - Pa
rse Error: [ext_resource] referenced nonexistent resource at: res://scene_script.gd

The scene tries to load a local resource (like a script) and it fails because the res:// path is now pointing to the project which is loading this external scene. Don’t know how to handle that.

rolfpancake | 2018-01-16 18:15

at least mobile platforms, is better to put external files on user data folder (OS.get_user_data_dir( ) ) and utilize user:// or search for Documents folder (try with OS.getsystemdir(OS.SYSTEMDIR_DOCUMENTS))

eons | 2018-01-16 22:30