diff --git a/core/io/resource.cpp b/core/io/resource.cpp index e0d42a274ac3..64fa597a677c 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -90,6 +90,10 @@ String Resource::get_path() const { return path_cache; } +void Resource::set_path_cache(const String &p_path) { + path_cache = p_path; +} + String Resource::generate_scene_unique_id() { // Generate a unique enough hash, but still user-readable. // If it's not unique it does not matter because the saver will try again. diff --git a/core/io/resource.h b/core/io/resource.h index a9b1a88f6bcc..610c2150dbaa 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -103,6 +103,7 @@ class Resource : public RefCounted { virtual void set_path(const String &p_path, bool p_take_over = false); String get_path() const; + void set_path_cache(const String &p_path); // Set raw path without involving resource cache. _FORCE_INLINE_ bool is_built_in() const { return path_cache.is_empty() || path_cache.contains("::") || path_cache.begins_with("local://"); } static String generate_scene_unique_id(); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index ea97e5ecce33..2a33f723dc8a 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -774,6 +774,8 @@ Error ResourceLoaderBinary::load() { res = Ref(r); if (!path.is_empty() && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) { r->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE); //if got here because the resource with same path has different type, replace it + } else if (!path.is_resource_file()) { + r->set_path_cache(path); } r->set_scene_unique_id(id); } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 6721ec095330..b1ebdff91fb0 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -341,6 +341,8 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { if (load_task.resource.is_valid()) { if (load_task.cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) { load_task.resource->set_path(load_task.local_path); + } else if (!load_task.local_path.is_resource_file()) { + load_task.resource->set_path_cache(load_task.local_path); } if (load_task.xl_remapped) { diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 6245cc85a0c6..a2be6a86d73b 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -992,6 +992,7 @@ void GDScript::set_path(const String &p_path, bool p_take_over) { String old_path = path; path = p_path; + path_valid = true; GDScriptCache::move_script(old_path, p_path); for (KeyValue> &kv : subclasses) { @@ -1000,6 +1001,9 @@ void GDScript::set_path(const String &p_path, bool p_take_over) { } String GDScript::get_script_path() const { + if (!path_valid && !get_path().is_empty()) { + return get_path(); + } return path; } @@ -1035,6 +1039,7 @@ Error GDScript::load_source_code(const String &p_path) { source = s; path = p_path; + path_valid = true; #ifdef TOOLS_ENABLED source_changed_cache = true; set_edited(false); diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 04b0a1d78671..9717dd7ff100 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -171,6 +171,7 @@ class GDScript : public Script { //exported members String source; String path; + bool path_valid = false; // False if using default path. StringName local_name; // Inner class identifier or `class_name`. StringName global_name; // `class_name`. String fully_qualified_name; diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index dd39f8835294..19718f12be22 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -577,6 +577,8 @@ Error ResourceLoaderText::load() { if (do_assign) { if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) { res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE); + } else if (!path.is_resource_file()) { + res->set_path_cache(path); } res->set_scene_unique_id(id); }