+1 vote

Hi there,

So I have a game that requires a lot of images, that I can then load at run time. I then go on to choose one of these images and load it. Rather than hardcode the list of image files, I have a function that browses the directory and looks for png files. My code to do so works perfectly while testing in the editor, but if I make a release build by exporting, my code fails to find any images.

Debugging shows that these resources are not included in the exported build (however, their .import files are.)
I have tried to fix this by making sure these images are covered by a glob pattern in the export filters, but this doesn't change anything.

Now, if I do hardcoded the list of image in code, they all load fine when running a release build, which leads me to believe the code is scanned for references to resources to be included. So how can i make this work?

Here is the code to load the image files. Note the debugging print statement, the output of which is below:

    if dir.open("res://tattoos/") == OK:
        var file_name = dir.get_next()
        while (file_name != ""):
                print("File name: ", file_name)  # Debugging release builds
                if file_name.ends_with("png"):
                        tattoos.push_back("res://tattoos/" + file_name)
                file_name = dir.get_next()
    return tattoos

If I run this from the editor, I get output like:

File name: anchor.png.import
File name: heart.png
File name: eye.png.import
File name: .
File name: new
File name: tear.png
File name: ..

But if I run this in an exported build, I get output like:

File name: new
File name: anchor.png.import
File name: book.png.import
File name: cross.png.import
File name: eye.png.import

My export settings are as follows:
Export settings

For reference, if I replace the above code with something like:

    var tattoos = [

It works fine in both builds.

Thanks in advance!

in Engine by (16 points)

1 Answer

+1 vote
Best answer

See my answer to a similar question here:


Hopefully, that's helpful...

by (19,272 points)
selected by

Thanks @jgodfrey - that works like a charm!

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.