My godot project refuses to export art and music assets [HELP]

Godot Version

4.2.2 stable

Question

90% of my game is build from a framework project I crafted that assign texture to sprite/texure rect by code only
forexample:

sprite.texure = resourceLoader.load(res://texure.png)

this is prettymuch how my game runs on. It is perfect when running inside godot engine. I am horrified and panicked right now when I exported the game to find out that they are all gone. My game has turned back into the empty template with only those embedded sprites. I tried to put *.txt, *.png, *.mp3, *.ogv for filter resource file to export and only txt worked. I set export mode to export all resources and then exported selected resources and selected all my assets and nothing works.

Help I’m panicking I worked a month on this :sob:
edit: the ogv works but the rest don’t
also I might need to be specific on how my “template” works
it reads line by line from a txt file, use regrex to filterout certain commands and execute them. most commands included the name of art/music asset and where to put them.
A recursion function will find the location of the asset in string and assign it to
the ralative sprite/texurerect by Resourceloader.load() method. It is extremely easy and flexible on editer until I decides to export the game

PNG should not disappear from the exported project :sweat_smile:
Unsupported extensions should be explicitly configured in the “filter to export non-resource files” in the export settings, as you pointed out already

However some operations are not available in the exported builds, but it’s hard to pinpoint the source of the problem without additional details on your “framework”. Could you give a more detailed example ? The content of your text file, the type of “commands” you’re trying to execute from it, etc.

1 Like

lets say I have a.png located under art folder under res://
the txt file will have a line as (sprite1, a.png)
the code will read the line and pass them into a function where “a.png” is passed into a recursive function that will return its exact location, aka “res://art//a.png”
then it will be sprite1.texure = Resourceloader.load(“res://art//a.png”) and a.png will show up as the texure of sprite1 in the game. Doesn’t work in export version though…

1 Like

please give details into this “recursive function that will return its exact location”. are you scanning the filesystem at runtime ?

1 Like
func _helper_search_file(directory: String, files: String):
	var direction = DirAccess.open(directory)
	if files not in direction.get_files() and direction.get_directories().is_empty():
		return null
	if files in DirAccess.open(directory).get_files():
		return directory + "/" + files
	else:
		for path in DirAccess.open(directory).get_directories():
			if _helper_search_file(directory +"/" + path+ "/", files) != null:
				return _helper_search_file(directory +"/" + path, files)
		return null

here is the full code, I suppose so

1 Like

ok this is the source of the problem :slight_smile:
Scanning filesystem at runtime will not work. Resources are exported to another folder, but they’re still “mapped” from their original filepath.
Therefore, when you know the exact path, ResourceLoader.load(path) works.
But if you try to “scan” the filesystem looking for the file, it won’t be there.

if you have a lot of resources mapped this way, I would suggest the following solution : create a static dictionary serialized in a file or a custom resource containing all the mappings (filename → filepath). you can use your existing recursive function to create this dictionary from a special scene that you will only run in editor.

This will also improve the performance of your code, since you won’t have to scan your filesystem every time you need one of the resource.

2 Likes

and there goes the core of my framework :melting_face: .
glad to know I can modify it and make it work, can you provide some doc for creating a custom resource? I want people with zero coding experience to understand and my framework nicely so it will really be helpful if the function can automatically map everything

1 Like

Start here : Resources — Godot Engine (stable) documentation in English

1 Like

ty! As for " a special scene that you will only run in editor.". How can I achieve that? I am thinking about creating a resource file and save it after running the editor for once, but I don’t think I can save files under res:// & modify saved resources under res://.

1 Like

you can perfectly open, modify and save resources under res:// from the editor.
a “special scene that only runs in the editor” is just a regular scene, that you won’t use at runtime :sweat_smile: only for “preparing” the magic dictionary (that must go in res:// indeed so it is shipped with the game)

2 Likes

so an independent scene that is not anyother scene’s child?

1 Like

any scene will work. it’s just that this scene will be dedicated to the purpose of “baking” your asset filepaths, which is something that you have to do by running from the editor (you cannot do it at runtime)

2 Likes

so an independent scene for me, ty again! Also I just realized a weird issue, some of my txt file is also loaded by the same way: Using the recursion function to find thier path during runtime by scanning the filesystem. However they appear to work, which is strange. :melting_face:

1 Like

TXT files are not resources in the eyes of Godot, therefore they are left untouched by Godot resource export mechanism

2 Likes

interesting, is there a way to set png and mp3 so they can bypass the godot resource export mechanism? I think it will be a great idea to implement the resource mapper (compiler in some way) but it will be better if I could export my current completed project right now.

1 Like

everything is possible. you can look into custom resource importers. but honestly i wouldn’t recommend bypassing godot texture import, because it’s directly hooked to compression mechanisms and optimization features.

i don’t really understand the use case for your framework really :sweat_smile: why do you need an additional layer of complexity on your resource mapping when you can just use godot directly ?

1 Like

Turns out its easier to build a mapper resource than I expected so yeah I asked a dumb question. The game I am making is a visual novel and the purpose for the framework is to just give people with literally zero coding skill to make their game with a simple command. So instead of having to understand gds script and nodes all they need to do is type (art1.png, left) to have the sprite on the left switch to art1 and (music.mp3) to switch music into what they want.
tbh the “extra layer” is just a sort of an additional feature as I pre-implement many vital game feature such as auto-play, saving&loading, setting system etc.
Although from what I am doing in here it seems that I have a long way to go :joy:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.