From d376b20befb3dc306e9ce1f6411498f0c177c51e Mon Sep 17 00:00:00 2001 From: DeeJayLSP Date: Wed, 15 Apr 2026 19:21:28 -0300 Subject: [PATCH] Exchange use of `ClassDB::is_parent_class()` with `Object::is_class()` where possible --- core/variant/container_type_validate.h | 4 ++-- editor/docks/scene_tree_dock.cpp | 3 +-- editor/inspector/editor_properties_array_dict.cpp | 7 +++---- editor/script/script_text_editor.cpp | 2 +- modules/gdscript/gdscript.cpp | 2 +- modules/gdscript/gdscript_function.cpp | 2 +- modules/gdscript/gdscript_utility_functions.cpp | 2 +- modules/gdscript/gdscript_vm.cpp | 8 ++++---- modules/mono/csharp_script.cpp | 6 +++--- modules/mono/glue/runtime_interop.cpp | 4 ++-- 10 files changed, 19 insertions(+), 21 deletions(-) diff --git a/core/variant/container_type_validate.h b/core/variant/container_type_validate.h index e76d172476..9d9f7702ad 100644 --- a/core/variant/container_type_validate.h +++ b/core/variant/container_type_validate.h @@ -110,9 +110,9 @@ private: } const StringName &obj_class = object->get_class_name(); - if (obj_class != class_name && !ClassDB::is_parent_class(obj_class, class_name)) { + if (obj_class != class_name && !object->is_class(class_name)) { if (p_output_errors) { - ERR_FAIL_V_MSG(false, vformat("Attempted to %s an object of type '%s' into a %s, which does not inherit from '%s'.", String(p_operation), object->get_class(), where, String(class_name))); + ERR_FAIL_V_MSG(false, vformat("Attempted to %s an object of type '%s' into a %s, which does not inherit from '%s'.", String(p_operation), obj_class, where, String(class_name))); } else { return false; } diff --git a/editor/docks/scene_tree_dock.cpp b/editor/docks/scene_tree_dock.cpp index 9efd905592..d73872c32d 100644 --- a/editor/docks/scene_tree_dock.cpp +++ b/editor/docks/scene_tree_dock.cpp @@ -651,7 +651,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { // Prefer nodes that inherit from the current scene root. Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene(); if (current_edited_scene_root) { - String root_class = current_edited_scene_root->get_class_name(); static Vector preferred_types; if (preferred_types.is_empty()) { preferred_types.push_back("Control"); @@ -660,7 +659,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } for (int i = 0; i < preferred_types.size(); i++) { - if (ClassDB::is_parent_class(root_class, preferred_types[i])) { + if (current_edited_scene_root->is_class(preferred_types[i])) { create_dialog->set_preferred_search_result_type(preferred_types[i]); break; } diff --git a/editor/inspector/editor_properties_array_dict.cpp b/editor/inspector/editor_properties_array_dict.cpp index 3250f79eb5..581f4e428e 100644 --- a/editor/inspector/editor_properties_array_dict.cpp +++ b/editor/inspector/editor_properties_array_dict.cpp @@ -646,7 +646,6 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const { return false; } - String res_type = res->get_class(); StringName script_class; if (res->get_script()) { script_class = EditorNode::get_singleton()->get_object_custom_type_name(res->get_script()); @@ -654,7 +653,7 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const { for (String at : allowed_type.split(",", false)) { at = at.strip_edges(); - if (ClassDB::is_parent_class(res_type, at) || EditorNode::get_editor_data().script_class_is_parent(script_class, at)) { + if (res->is_class(at) || EditorNode::get_editor_data().script_class_is_parent(script_class, at)) { return true; } } @@ -684,7 +683,7 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const { ERR_FAIL_NULL_V_MSG(dropped_node, false, "Could not get the dropped node by its path."); if (allowed_type != "NodePath") { - if (!ClassDB::is_parent_class(dropped_node->get_class_name(), allowed_type) && + if (!dropped_node->is_class(allowed_type) && !EditorNode::get_singleton()->is_object_of_custom_type(dropped_node, allowed_type)) { // Fail if one of the nodes is not of allowed type. return false; @@ -696,7 +695,7 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const { if (!allowed_subtype_array.has(dropped_node->get_class_name())) { // The dropped node type was not found in the allowed subtype array, we must check if it inherits one of them. for (const String &ast : allowed_subtype_array) { - if (ClassDB::is_parent_class(dropped_node->get_class_name(), ast) || + if (dropped_node->is_class(ast) || EditorNode::get_singleton()->is_object_of_custom_type(dropped_node, ast)) { is_drop_allowed = true; break; diff --git a/editor/script/script_text_editor.cpp b/editor/script/script_text_editor.cpp index bca7adb364..724df3ab9f 100644 --- a/editor/script/script_text_editor.cpp +++ b/editor/script/script_text_editor.cpp @@ -2036,7 +2036,7 @@ static String _get_dropped_resource_as_member(const Ref &p_resource, b path = ResourceUID::get_singleton()->id_to_text(id); } } - const bool is_script = ClassDB::is_parent_class(p_resource->get_class(), "Script"); + const bool is_script = p_resource->is_class(SNAME("Script")); if (!p_create_field) { return vformat("preload(%s)", _quote_drop_data(path)); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 0fb2de8914..0f3ee2a3aa 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -412,7 +412,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) { } if (top->native.is_valid()) { - if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) { + if (!p_this->is_class(top->native->get_name())) { if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->debug_break_parse(_get_debug_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be assigned to an object of type: '" + p_this->get_class() + "'"); } diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 2925e2d59e..069d1d8ef9 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -114,7 +114,7 @@ bool GDScriptDataType::is_type(const Variant &p_variant, bool p_allow_implicit_c return !was_freed; } - if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) { + if (!obj->is_class(native_type)) { return false; } return true; diff --git a/modules/gdscript/gdscript_utility_functions.cpp b/modules/gdscript/gdscript_utility_functions.cpp index 5241295c56..651e7e28b2 100644 --- a/modules/gdscript/gdscript_utility_functions.cpp +++ b/modules/gdscript/gdscript_utility_functions.cpp @@ -478,7 +478,7 @@ struct GDScriptUtilityFunctionsDefinitions { GDScriptNativeClass *native_type = Object::cast_to(type_object); if (native_type) { - *r_ret = ClassDB::is_parent_class(value_object->get_class_name(), native_type->get_name()); + *r_ret = value_object->is_class(native_type->get_name()); return; } diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index b470b15872..3b9a4e58d1 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -946,7 +946,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE_BREAK; } - *dst = object && ClassDB::is_parent_class(object->get_class_name(), native_type); + *dst = object && object->is_class(native_type); ip += 4; } DISPATCH_OPCODE; @@ -1553,7 +1553,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE_BREAK; } - if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) { + if (src_obj && !src_obj->is_class(nc->get_name())) { err_text = "Trying to assign value of type '" + src_obj->get_class_name() + "' to a variable of type '" + nc->get_name() + "'."; OPCODE_BREAK; @@ -1674,7 +1674,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #endif Object *src_obj = src->operator Object *(); - if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) { + if (src_obj && !src_obj->is_class(nc->get_name())) { *dst = Variant(); // invalid cast, assign NULL } else { *dst = *src; @@ -2948,7 +2948,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #else Object *ret_obj = r->operator Object *(); #endif // DEBUG_ENABLED - if (ret_obj && !ClassDB::is_parent_class(ret_obj->get_class_name(), nc->get_name())) { + if (ret_obj && !ret_obj->is_class(nc->get_name())) { #ifdef DEBUG_ENABLED err_text = vformat(R"(Trying to return a value of type "%s" from a function whose return type is "%s".)", _get_var_type(r), nc->get_name()); diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 6fc8a5edd1..3fc4ead197 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -894,7 +894,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { continue; } - if (!ClassDB::is_parent_class(obj->get_class_name(), native_name)) { + if (!obj->is_class(native_name)) { // No longer inherits the same compatible type, can't reload scr->pending_reload_state.erase(obj_id); continue; @@ -1158,7 +1158,7 @@ bool CSharpLanguage::setup_csharp_script_binding(CSharpScriptBinding &r_script_b ERR_FAIL_NULL_V(classinfo, false); type_name = classinfo->gdtype->get_name(); - bool parent_is_object_class = ClassDB::is_parent_class(p_object->get_class_name(), type_name); + bool parent_is_object_class = p_object->is_class(type_name); ERR_FAIL_COND_V_MSG(!parent_is_object_class, false, "Type inherits from native type '" + type_name + "', so it can't be instantiated in object of type: '" + p_object->get_class() + "'."); @@ -2464,7 +2464,7 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { ERR_FAIL_COND_V(native_name == StringName(), nullptr); - if (!ClassDB::is_parent_class(p_this->get_class_name(), native_name)) { + if (!p_this->is_class(native_name)) { if (EngineDebugger::is_active()) { CSharpLanguage::get_singleton()->debug_break_parse(get_path(), 0, "Script inherits from native type '" + String(native_name) + diff --git a/modules/mono/glue/runtime_interop.cpp b/modules/mono/glue/runtime_interop.cpp index 2026407c03..e3bf2b7e4e 100644 --- a/modules/mono/glue/runtime_interop.cpp +++ b/modules/mono/glue/runtime_interop.cpp @@ -278,7 +278,7 @@ GCHandleIntPtr godotsharp_internal_unmanaged_instance_binding_create_managed(Obj CRASH_COND(script_binding.type_name == StringName()); #endif - bool parent_is_object_class = ClassDB::is_parent_class(p_unmanaged->get_class_name(), script_binding.type_name); + bool parent_is_object_class = p_unmanaged->is_class(script_binding.type_name); ERR_FAIL_COND_V_MSG(!parent_is_object_class, { nullptr }, "Type inherits from native type '" + script_binding.type_name + "', so it can't be instantiated in object of type: '" + p_unmanaged->get_class() + "'."); @@ -356,7 +356,7 @@ void godotsharp_array_filter_godot_objects_by_native(StringName *p_native_name, memnew_placement(r_output, Array); for (int i = 0; i < p_input->size(); ++i) { - if (ClassDB::is_parent_class(((Object *)(*p_input)[i])->get_class(), *p_native_name)) { + if (((Object *)(*p_input)[i])->is_class(*p_native_name)) { r_output->push_back(p_input[i]); } }