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

+2 votes

Hi, I'm working on a card game, with a certain amount of cards that can change as the development process progresses.
All the card images are in a forlder inside the project, I made a card object which I instance and store dinamically as many times as images I have, and inject the image at creation time using the load() method.

Everything works fine on the editor, but once I Export, the game doesn't seem to find the images, except the one I manually added to the card object scene as a working reference.

this makes me think that the engine isn't aware that it should export these resources, I added the .jpg extension an the path/folder/to/images/ to the exporter filters, and made sure that the path to the res folders is correct. how can I export the images to be recognized?

As a side note: when I collect the files using ".jpg.import" in my code's conditional instead of ".jpg", it finds the files but can't iterpret them, which I guess must be normal.

here's also a bit of the relevant parts of my code. Thank you in advance for your help, I have tried a bunch of things and nothing seems to work.

Collecting the files:

func list_files_in_directory(path:String,extension:String)->Array:
var files:Array = []
var dir:Directory =
var safecounter:int = 0
while true and safecounter<500:
    var file:String = dir.get_next()
    if file == "":
        print("safecounter: =" + String(safecounter))
    elif not file.begins_with("."):
        if file.ends_with(extension):


return files

Loading the data from the filePaths:

func CreateCards()->Array:  
    var tempcardspath:Array = list_files_in_directory(cardsDir,"jpg")#jpg.import
    var tempCards:Array = []
    for tempcard in tempcardspath:
        var thisCard:String = tempcard
        var card:Card  = cardObj.instance()
        var imagePath:String = cardsDir+tempcard
        var cardTexture:Texture = load(imagePath)
        var cardID:String = (thisCard.split("_",false,1)[1]).split(".",false,1)[0]
        card.cardID = cardID
        card.cardImage = cardTexture
    return tempCards

paths to card object and to the images:

var cardsDir:String = "res://Art/Cards/MainDeck/"
onready var cardObj:PackedScene = preload("res://Scenes/Card.tscn")
in Engine by (22 points)

I'm having the same issue as well (godot 3.2.1), I'd be interested to know if you solve it.

1 Answer

+2 votes

OK, Finally found a solution in here:

if you do go this way, you'll probably have to handle part of the code executed in editor and part when exported, for this, you can ise something like:

var isOnBuild:bool = false


if OS.has_feature("standalone"):
    print("Running an exported build.")
    isOnBuild = true
    print("Running from the editor.")


Finally, on the function that collects the paths

if isOnBuild:# exported version
            if file.ends_with('.import'):  
                var file_name = file.replace('.import', '')
                if file_name.ends_with(fileextension):
        else:# in editor version
            if file.ends_with(fileextension):  

Hope this helps!

by (22 points)

That's what I found as well, although the standalone bit is genious :) I found it very late (local time) so I went to get some zees.

From what I can understand, plain load does not have this ability, but you will need ResourceLoader.load to load the resource afterwards.

Ok, taht's very good to know! I'll check with ResourceLoader.load to see if it's possible to skip all the management

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.