Load lots of resource at run-time

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

Is there a way to load a lot of resources at Run-Time. Example if I have a bunch of images I wanted to load into an array/List off of the hard-disk. If not how would I go about doing so?

:bust_in_silhouette: Reply From: Freeman

You could use preloading.
The is a documentation and a simple example:

That says (exact copy):

Loading resources from code is easy, there are two ways to do it. The first is to use load(), like this:

func _ready():
        var res = load("res://robi.png") # resource is loaded when line is executed

The second way is more optimal, but only works with a string constant parameter, because it loads the resource at compile-time.

func _ready():
        var res = preload("res://robi.png") # resource is loaded at compile time

Reading about the background loading might be helpful as well, if you plan to create progress bar for player to see the progress of loading the resources:

Thanks for the reply but not quite what I’m looking for. Maybe I should explain a bit more. I want to load an entire resource folder full of images into an array at run-time. What I want to know is there a way to do this all at once stead of one by one?

vonflyhighace2 | 2016-04-08 23:56

:bust_in_silhouette: Reply From: eaglecat

this is an very simple example of loading resources

var resources = Array()

func simpleLoad(var dirPath):
	var dir = Directory.new()
	var file_name = dir.get_next()

		if dir.current_is_dir():
		file_name = dir.get_next()