@@ -722,13 +722,32 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type
722722 }
723723 } else if (ProjectSettings::get_singleton ()->has_autoload (first) && ProjectSettings::get_singleton ()->get_autoload (first).is_singleton ) {
724724 const ProjectSettings::AutoloadInfo &autoload = ProjectSettings::get_singleton ()->get_autoload (first);
725- Ref<GDScriptParserRef> ref = parser->get_depended_parser_for (autoload.path );
725+ String script_path;
726+ if (ResourceLoader::get_resource_type (autoload.path ) == " PackedScene" ) {
727+ // Try to get script from scene if possible.
728+ if (GDScriptLanguage::get_singleton ()->has_any_global_constant (autoload.name )) {
729+ Variant constant = GDScriptLanguage::get_singleton ()->get_any_global_constant (autoload.name );
730+ Node *node = Object::cast_to<Node>(constant);
731+ if (node != nullptr ) {
732+ Ref<GDScript> scr = node->get_script ();
733+ if (scr.is_valid ()) {
734+ script_path = scr->get_script_path ();
735+ }
736+ }
737+ }
738+ } else if (ResourceLoader::get_resource_type (autoload.path ) == " GDScript" ) {
739+ script_path = autoload.path ;
740+ }
741+ if (script_path.is_empty ()) {
742+ return bad_type;
743+ }
744+ Ref<GDScriptParserRef> ref = parser->get_depended_parser_for (script_path);
726745 if (ref.is_null ()) {
727- push_error (vformat (R"( The referenced autoload "%s" (from "%s") could not be loaded.)" , first, autoload. path ), p_type);
746+ push_error (vformat (R"( The referenced autoload "%s" (from "%s") could not be loaded.)" , first, script_path ), p_type);
728747 return bad_type;
729748 }
730749 if (ref->raise_status (GDScriptParserRef::INHERITANCE_SOLVED) != OK) {
731- push_error (vformat (R"( Could not parse singleton "%s" from "%s".)" , first, autoload. path ), p_type);
750+ push_error (vformat (R"( Could not parse singleton "%s" from "%s".)" , first, script_path ), p_type);
732751 return bad_type;
733752 }
734753 result = ref->get_parser ()->head ->get_datatype ();
0 commit comments