浏览代码

Add error message when a GDScript resource fails to load.

Currently, GDScripts who are only loaded through `ResourceLoader::load()`,
like Autoloads, do not have a pathway to announce there is an error in their
code. This contributes to significant confusion in error projects when
autoloads are involved. At least partially closes #78230.

(cherry picked from commit cca57171c16c90d6acec4e0eef1ed904973bcb20)
ocean (they/them) 2 年之前
父节点
当前提交
0b38cf8a8d
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      modules/gdscript/gdscript.cpp

+ 5 - 0
modules/gdscript/gdscript.cpp

@@ -2700,6 +2700,11 @@ Ref<Resource> ResourceFormatLoaderGDScript::load(const String &p_path, const Str
 	Error err;
 	Error err;
 	Ref<GDScript> scr = GDScriptCache::get_full_script(p_path, err, "", p_cache_mode == CACHE_MODE_IGNORE);
 	Ref<GDScript> scr = GDScriptCache::get_full_script(p_path, err, "", p_cache_mode == CACHE_MODE_IGNORE);
 
 
+	if (err && scr.is_valid()) {
+		// If !scr.is_valid(), the error was likely from scr->load_source_code(), which already generates an error.
+		ERR_PRINT_ED(vformat(R"(Failed to load script "%s" with error "%s".)", p_path, error_names[err]));
+	}
+
 	if (r_error) {
 	if (r_error) {
 		// Don't fail loading because of parsing error.
 		// Don't fail loading because of parsing error.
 		*r_error = scr.is_valid() ? OK : err;
 		*r_error = scr.is_valid() ? OK : err;