Skip to content

Commit 2584f75

Browse files
committed
Merge pull request #96499 from beev1s/shallow-script-cache-error
Fix resource loader not resolving shallow loaded scripts through dependencies
2 parents 07e759b + fd5fc9f commit 2584f75

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

modules/gdscript/gdscript.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,26 @@ void GDScript::_bind_methods() {
10751075
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDScript::_new, MethodInfo("new"));
10761076
}
10771077

1078+
void GDScript::set_path_cache(const String &p_path) {
1079+
if (ResourceCache::has(p_path)) {
1080+
set_path(p_path, true);
1081+
return;
1082+
}
1083+
1084+
if (is_root_script()) {
1085+
Script::set_path_cache(p_path);
1086+
}
1087+
1088+
String old_path = path;
1089+
path = p_path;
1090+
path_valid = true;
1091+
GDScriptCache::move_script(old_path, p_path);
1092+
1093+
for (KeyValue<StringName, Ref<GDScript>> &kv : subclasses) {
1094+
kv.value->set_path_cache(p_path);
1095+
}
1096+
}
1097+
10781098
void GDScript::set_path(const String &p_path, bool p_take_over) {
10791099
if (is_root_script()) {
10801100
Script::set_path(p_path, p_take_over);

modules/gdscript/gdscript.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ class GDScript : public Script {
300300

301301
virtual Error reload(bool p_keep_state = false) override;
302302

303+
virtual void set_path_cache(const String &p_path) override;
303304
virtual void set_path(const String &p_path, bool p_take_over = false) override;
304305
String get_script_path() const;
305306
Error load_source_code(const String &p_path);

modules/gdscript/gdscript_cache.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, Error &r_e
312312

313313
Ref<GDScript> script;
314314
script.instantiate();
315-
script->set_path(p_path, true);
315+
script->set_path_cache(p_path);
316316
if (remapped_path.get_extension().to_lower() == "gdc") {
317317
Vector<uint8_t> buffer = get_binary_tokens(remapped_path);
318318
if (buffer.is_empty()) {
@@ -360,6 +360,7 @@ Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_erro
360360
return script;
361361
}
362362
}
363+
script->set_path(p_path, true);
363364

364365
const String remapped_path = ResourceLoader::path_remap(p_path);
365366

0 commit comments

Comments
 (0)