-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register the export info correctly when a script is used as the variable type for Node #90487
Register the export info correctly when a script is used as the variable type for Node #90487
Conversation
dc699a4
to
4ddb6dc
Compare
4ddb6dc
to
6e7aea9
Compare
6e7aea9
to
def8cc0
Compare
def8cc0
to
5eed3b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for delay. Here's my suggestion for making CLASS
and SCRIPT
cases consistent:
Patch
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index da599bf57b..771ccf47b7 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -4327,11 +4327,11 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
if (ClassDB::is_parent_class(export_type.native_type, SNAME("Resource"))) {
variable->export_info.type = Variant::OBJECT;
variable->export_info.hint = PROPERTY_HINT_RESOURCE_TYPE;
- variable->export_info.hint_string = export_type.to_string();
+ variable->export_info.hint_string = class_name;
} else if (ClassDB::is_parent_class(export_type.native_type, SNAME("Node"))) {
variable->export_info.type = Variant::OBJECT;
variable->export_info.hint = PROPERTY_HINT_NODE_TYPE;
- variable->export_info.hint_string = export_type.to_string();
+ variable->export_info.hint_string = class_name;
} else {
push_error(R"(Export type can only be built-in, a resource, a node, or an enum.)", p_annotation);
return false;
@@ -4340,27 +4340,24 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
case GDScriptParser::DataType::SCRIPT: {
StringName class_name;
- StringName native_base;
if (export_type.script_type.is_valid()) {
- class_name = export_type.script_type->get_language()->get_global_class_name(export_type.script_type->get_path());
- native_base = export_type.script_type->get_instance_base_type();
+ class_name = export_type.script_type->get_global_name();
}
if (class_name == StringName()) {
Ref<Script> script = ResourceLoader::load(export_type.script_path, SNAME("Script"));
if (script.is_valid()) {
- class_name = script->get_language()->get_global_class_name(export_type.script_path);
- native_base = script->get_instance_base_type();
+ class_name = script->get_global_name();
}
}
if (class_name == StringName()) {
push_error(R"(Script export type must be a global class.)", p_annotation);
return false;
}
- if (native_base != StringName() && ClassDB::is_parent_class(native_base, SNAME("Resource"))) {
+ if (ClassDB::is_parent_class(export_type.native_type, SNAME("Resource"))) {
variable->export_info.type = Variant::OBJECT;
variable->export_info.hint = PROPERTY_HINT_RESOURCE_TYPE;
variable->export_info.hint_string = class_name;
- } else if (native_base != StringName() && ClassDB::is_parent_class(native_base, SNAME("Node"))) {
+ } else if (ClassDB::is_parent_class(export_type.native_type, SNAME("Node"))) {
variable->export_info.type = Variant::OBJECT;
variable->export_info.hint = PROPERTY_HINT_NODE_TYPE;
variable->export_info.hint_string = class_name;
modules/gdscript/tests/scripts/parser/features/export_variable.gd
Outdated
Show resolved
Hide resolved
5eed3b9
to
590763a
Compare
modules/gdscript/tests/scripts/parser/features/export_variable.gd
Outdated
Show resolved
Hide resolved
… as the variable type for Node
590763a
to
653a8b1
Compare
Thanks! |
this merge seems to break spatial gardener (and, looks like, anything that extends with a script path instead of a class name) |
@shakesoda Please open a new issue if you find a regression. Note that |
This PR fixes #73993
It will allow a preloaded const script to be used as the type of an exported variable in GDScript