Skip to content

Commit d0826b0

Browse files
committed
Fix external resource IDs being lost for default properties
1 parent 2d113cc commit d0826b0

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

core/io/resource.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -672,25 +672,25 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
672672
}
673673

674674
// Helps keep IDs the same when loading/saving scenes. An empty ID clears the entry, and an empty ID is returned when not found.
675-
void Resource::set_id_for_path(const String &p_path, const String &p_id) {
675+
void Resource::set_resource_id_for_path(const String &p_referrer_path, const String &p_resource_path, const String &p_id) {
676676
#ifdef TOOLS_ENABLED
677677
if (p_id.is_empty()) {
678678
ResourceCache::path_cache_lock.write_lock();
679-
ResourceCache::resource_path_cache[p_path].erase(get_path());
679+
ResourceCache::resource_path_cache[p_referrer_path].erase(p_resource_path);
680680
ResourceCache::path_cache_lock.write_unlock();
681681
} else {
682682
ResourceCache::path_cache_lock.write_lock();
683-
ResourceCache::resource_path_cache[p_path][get_path()] = p_id;
683+
ResourceCache::resource_path_cache[p_referrer_path][p_resource_path] = p_id;
684684
ResourceCache::path_cache_lock.write_unlock();
685685
}
686686
#endif
687687
}
688688

689-
String Resource::get_id_for_path(const String &p_path) const {
689+
String Resource::get_id_for_path(const String &p_referrer_path) const {
690690
#ifdef TOOLS_ENABLED
691691
ResourceCache::path_cache_lock.read_lock();
692-
if (ResourceCache::resource_path_cache[p_path].has(get_path())) {
693-
String result = ResourceCache::resource_path_cache[p_path][get_path()];
692+
if (ResourceCache::resource_path_cache[p_referrer_path].has(get_path())) {
693+
String result = ResourceCache::resource_path_cache[p_referrer_path][get_path()];
694694
ResourceCache::path_cache_lock.read_unlock();
695695
return result;
696696
} else {

core/io/resource.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ class Resource : public RefCounted {
181181
virtual RID get_rid() const; // Some resources may offer conversion to RID.
182182

183183
// Helps keep IDs the same when loading/saving scenes. An empty ID clears the entry, and an empty ID is returned when not found.
184-
void set_id_for_path(const String &p_path, const String &p_id);
185-
String get_id_for_path(const String &p_path) const;
184+
static void set_resource_id_for_path(const String &p_referrer_path, const String &p_resource_path, const String &p_id);
185+
void set_id_for_path(const String &p_referrer_path, const String &p_id) { set_resource_id_for_path(p_referrer_path, get_path(), p_id); }
186+
String get_id_for_path(const String &p_referrer_path) const;
186187

187188
Resource();
188189
~Resource();

scene/resources/resource_format_text.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ Error ResourceLoaderText::_parse_ext_resource(VariantParser::Stream *p_stream, R
157157
}
158158
}
159159
} else {
160-
#ifdef TOOLS_ENABLED
161-
//remember ID for saving
162-
res->set_id_for_path(local_path, id);
163-
#endif
164160
r_res = res;
165161
}
166162
} else {
@@ -486,6 +482,13 @@ Error ResourceLoaderText::load() {
486482
resource_current++;
487483
}
488484

485+
#ifdef TOOLS_ENABLED
486+
for (const KeyValue<String, ExtResource> &E : ext_resources) {
487+
// Remember ID for saving.
488+
Resource::set_resource_id_for_path(local_path, E.value.path, E.key);
489+
}
490+
#endif
491+
489492
//these are the ones that count
490493
resources_total -= resource_current;
491494
resource_current = 0;

0 commit comments

Comments
 (0)