When a resource is loaded, the function setup_local_to_scene() is supposed to be called. And it's possible to override the virtual function _setup_local_to_scene in order to add custom behaviour.
However, I cannot get this to work. The virtual method is not called. I have set the flag resource_local_to_scene.
I can make it work by manually calling setup_local_to_scene(), like in this function which loads resources from a folder:
static func load_resources_from_folder(path_dir):
var result = []
var dir = Directory.new()
dir.change_dir(path_dir)
dir.list_dir_begin()
var path_file = dir.get_next()
while path_file != "":
if !dir.current_is_dir():
var resource = load(path_dir + path_file)
if resource.is_local_to_scene():
resource.setup_local_to_scene() # call manually
result.append(resource)
path_file = dir.get_next()
return result
But according to the documentation for the Resource class, setup_local_to_scene() should have been called inside the call to load():
void setup_local_to_scene ( )
This method is called when a resource with resource_local_to_scene enabled is loaded from a PackedScene instantiation. Its behavior can be customized by overriding _setup_local_to_scene from script.
var resource = load(path_dir + path_file)
but it seems that it doesn't get called. I have to manually add the next two lines of code.
Has anybody got this to work, or could it be a bug so I should file a bug report?