Allow writing resource.ext
instead of preload("res://path/to/resource.ext")
#4841
Replies: 3 comments 3 replies
-
This would just be messy. You can use relative paths like I do however think that preload-statements could be updated automatically when moving things, just like it works when moving resources referenced in scenes. |
Beta Was this translation helpful? Give feedback.
-
Consider using the ResourcePreloader node (added in Godot 3.1) and moving files using the FileSystem dock. It was designed specifically to address this problem 🙂 |
Beta Was this translation helpful? Give feedback.
-
What about have an in-editor table of "aliases", similar to an autoload/singleton, but built-in in the editor. Then if it needs to be used at run-time either on debug mode or for exported projects, the compiler replaces the aliases with the actual paths. If in-editor you only would be able to select a certain file, and let the path get updated automatically on re-ubication, would be great. |
Beta Was this translation helpful? Give feedback.
-
PROBLEM:
Strinlgy referencing (such as in
preload
ing) resources in scripts has a big drawback: moving the file, renaming it or renaming any of its parent folders breaks the link and it has to be updated sometimes in several scripts.SOLUTION:
But we know that at project export, res:// is set and will remain unchanged.
That means that file paths can at least be resolved at export time!
So consider the following code:
I'm proposing that instead we're allowed to write:
And it will be turned into the first example at export time.
preload(res("filename.ext")) -> preload("res://path/filename.ext")
. I like the idea of such a function with a short name (liketr
) but it could also berespath
.player/Head.gd
,preload(res("Enemy B/eye.png"))
This is actually two ideas in one:
Also/Alternatively automatic resource path resolution could be provided in the form of a specific notation much like
$
can precede an unquoted node path, we could have a character or special quote too likeres:"resource.ext"
orres/resource.ext
or something.Beta Was this translation helpful? Give feedback.
All reactions