summaryrefslogtreecommitdiffstats
path: root/core/io/resource_importer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/resource_importer.cpp')
-rw-r--r--core/io/resource_importer.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp
index b4c43abe00..a572dd562e 100644
--- a/core/io/resource_importer.cpp
+++ b/core/io/resource_importer.cpp
@@ -35,6 +35,8 @@
#include "core/os/os.h"
#include "core/variant/variant_parser.h"
+ResourceFormatImporterLoadOnStartup ResourceImporter::load_on_startup = nullptr;
+
bool ResourceFormatImporter::SortImporterByName::operator()(const Ref<ResourceImporter> &p_a, const Ref<ResourceImporter> &p_b) const {
return p_a->get_importer_name() < p_b->get_importer_name();
}
@@ -137,6 +139,20 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
}
Ref<Resource> ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
+#ifdef TOOLS_ENABLED
+ // When loading a resource on startup, we use the load_on_startup callback,
+ // which executes the loading in the EditorFileSystem. It can reimport
+ // the resource and retry the load, allowing the resource to be loaded
+ // even if it is not yet imported.
+ if (ResourceImporter::load_on_startup != nullptr) {
+ return ResourceImporter::load_on_startup(this, p_path, r_error, p_use_sub_threads, r_progress, p_cache_mode);
+ }
+#endif
+
+ return load_internal(p_path, r_error, p_use_sub_threads, r_progress, p_cache_mode, false);
+}
+
+Ref<Resource> ResourceFormatImporter::load_internal(const String &p_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode, bool p_silence_errors) {
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
@@ -148,6 +164,13 @@ Ref<Resource> ResourceFormatImporter::load(const String &p_path, const String &p
return Ref<Resource>();
}
+ if (p_silence_errors) {
+ // Note: Some importers do not create files in the .godot folder, so we need to check if the path is empty.
+ if (!pat.path.is_empty() && !FileAccess::exists(pat.path)) {
+ return Ref<Resource>();
+ }
+ }
+
Ref<Resource> res = ResourceLoader::_load(pat.path, p_path, pat.type, p_cache_mode, r_error, p_use_sub_threads, r_progress);
#ifdef TOOLS_ENABLED