Skip to content

Commit fd5fc9f

Browse files
author
Moritz Burgdorff
committed
Fixed resource loader using not fully loaded scripts
1 parent 7c38376 commit fd5fc9f

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

modules/gdscript/gdscript.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,26 @@ void GDScript::_bind_methods() {
10571057
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDScript::_new, MethodInfo("new"));
10581058
}
10591059

1060+
void GDScript::set_path_cache(const String &p_path) {
1061+
if (ResourceCache::has(p_path)) {
1062+
set_path(p_path, true);
1063+
return;
1064+
}
1065+
1066+
if (is_root_script()) {
1067+
Script::set_path_cache(p_path);
1068+
}
1069+
1070+
String old_path = path;
1071+
path = p_path;
1072+
path_valid = true;
1073+
GDScriptCache::move_script(old_path, p_path);
1074+
1075+
for (KeyValue<StringName, Ref<GDScript>> &kv : subclasses) {
1076+
kv.value->set_path_cache(p_path);
1077+
}
1078+
}
1079+
10601080
void GDScript::set_path(const String &p_path, bool p_take_over) {
10611081
if (is_root_script()) {
10621082
Script::set_path(p_path, p_take_over);

modules/gdscript/gdscript.h

+1
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, Error &r_e
311311

312312
Ref<GDScript> script;
313313
script.instantiate();
314-
script->set_path(p_path, true);
314+
script->set_path_cache(p_path);
315315
if (remapped_path.get_extension().to_lower() == "gdc") {
316316
Vector<uint8_t> buffer = get_binary_tokens(remapped_path);
317317
if (buffer.is_empty()) {
@@ -358,6 +358,7 @@ Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_erro
358358
return script;
359359
}
360360
}
361+
script->set_path(p_path, true);
361362

362363
if (p_update_from_disk) {
363364
if (p_path.get_extension().to_lower() == "gdc") {

0 commit comments

Comments
 (0)