The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

Big bad errors

I'm building a simple character creator.

The character is its own scene, with each customizable part being a sprite with a script attached. In the script I have a function which imports all files in a given path, and stores the files in an array - so for example the hair:


The directory contains a around 5-6 png files with different color variations of the hair. File 1 is array[0], file 2 is array[1], and so on.

I then have a button in the main scene which will increment the array index by one, and apply the texture. (it loops back to 0 if it goes too far).

This works well when I run the project from the editor, however if I run the exported exe, the files are not imported and the array will be empty, throwing the error in the screenshot. I've tried exporting all files in the project but I still have the same issue.

Any idea whats going on here?

Godot version v3.3.2
in Engine by (23 points)

1 Answer

+1 vote
Best answer

Hi, the docs for Directory say:

Note: Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. Use ResourceLoader to access imported resources.

This means that your files are no longer found in their original location. You must look for the import files instead.

Like this:

if not dir.current_is_dir() and file_name.ends_with(".import"):
    array.append(load(path + file_name.replace(".import, "")))
by (8,550 points)
selected by

Ok, changing the file check to .import in my function worked a charm. thanks mate!
One thing that I'm not quite clear about though, what does the dir.current_is_dir() in your if statement do? Mine seems to work without it.

Working code for anyone interested:

# path is the system path in string format
func get_files(path):

   # files stores all files in the path, which I append to the outer array
    var files = [] # stores the files, I add an array 
    var dir =

    if == OK:

        var current_file = dir.get_next()

        while current_file != "":
            if current_file.ends_with(".import"):
                var new_file_object = load(path + "/" + current_file.replace(".import",""))

            current_file = dir.get_next()


Yeah, you don't need it. It just checks if the current file in the directory is a folder or not.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.