-
-
Notifications
You must be signed in to change notification settings - Fork 24.2k
GDScript: Fix loading of GDScript resource imported from another file extension
#115381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
GDScript: Fix loading of GDScript resource imported from another file extension
#115381
Conversation
dalexeev
commented
Jan 26, 2026
- Fixes Can't load properly GDScript that is generated code saved by ResourceSaver.save in EditorImportPlugin #105299.
|
Please note that there may be a bug in the core. It's somewhat odd that godot/core/io/resource_loader.cpp Lines 306 to 318 in d5edd4a
godot/modules/gdscript/gdscript.cpp Lines 2918 to 2921 in d5edd4a
|
| Error err; | ||
| bool ignoring = p_cache_mode == CACHE_MODE_IGNORE || p_cache_mode == CACHE_MODE_IGNORE_DEEP; | ||
| Ref<GDScript> scr = GDScriptCache::get_full_script(p_original_path, err, "", ignoring); | ||
| Ref<GDScript> scr = GDScriptCache::get_full_script(target_path, err, "", ignoring); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Ref<GDScript> scr = GDScriptCache::get_full_script(target_path, err, "", ignoring); | |
| Ref<GDScript> scr = GDScriptCache::get_full_script(ResourceLoader::import_remap(p_original_path), err, "", ignoring); |
Wouldn't this basically be the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. GDScriptCache::get_full_script() already calls ResourceLoader::path_remap(), but that's a different method and doesn't help. Perhaps there's a difference between importers and format loaders.
godot/modules/gdscript/gdscript_cache.cpp
Line 365 in 780b689
| const String remapped_path = ResourceLoader::path_remap(p_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand the system, there are two parts to how a path maps to something that can be loaded from the pck.
Path changes that happen at import time. And path changes which happen at export time.
I suspect path_remap only takes care of the later, while import_remap takes care of the former. For a full transformation they need to be chained. This seems to be supported by my limited testing:
p_path: res://TestScene.gdc
p_original_path: res://TestScene.gd
ResourceLoader::import_remap(p_original_path): res://TestScene.gd
ResourceLoader::path_remap(p_original_path): res://TestScene.gdc
ResourceLoader::path_remap(ResourceLoader::import_remap(p_original_path)): res://TestScene.gdc
p_path: res://.godot/imported/import_test_target.test-f75ad55ac69400bc5d60d5af43574001.gd
p_original_path: res://import_test_target.test
ResourceLoader::import_remap(p_original_path): res://.godot/imported/import_test_target.test-f75ad55ac69400bc5d60d5af43574001.gd
ResourceLoader::path_remap(p_original_path): res://import_test_target.test
ResourceLoader::path_remap(ResourceLoader::import_remap(p_original_path)): res://.godot/imported/import_test_target.test-f75ad55ac69400bc5d60d5af43574001.gd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also worth noting, that the export plugin which does binary tokenization does not seem to account for import remaps. Which is why using p_path has the same behaviour as import_remap(original_path). But in theory if there was a path that was import and export remapped they would not be equivalent from my understanding
|
The main issue I have with this, is that it will result in a state were the IMO if we want to support this on a best effort basis we should use the |
I had this idea, but I'm unsure about choosing between strict behavior and best effort support (without guarantees the absence of weird bugs). I submitted this PR as is because: 1. the issue is labeled as a regression, and 2. at first glance, this fix looks like it should work. Given that you also support a stricter option, I'll probably update the PR as you suggested. This also makes sense in the long term (if we abandon the "script is a resource" approach in Godot 5). However, we still face the question: should we make this a strict error or just a warning? For example, we could use the |
|
I think the best middle ground right now would be:
|