Browse Source

Don't allow instancing virtual node types in the Create New Node dialog

Aaron Franke 2 years ago
parent
commit
ba542444e3
2 changed files with 11 additions and 5 deletions
  1. 7 1
      core/object/class_db.cpp
  2. 4 4
      editor/create_dialog.cpp

+ 7 - 1
core/object/class_db.cpp

@@ -31,6 +31,7 @@
 #include "class_db.h"
 #include "class_db.h"
 
 
 #include "core/config/engine.h"
 #include "core/config/engine.h"
+#include "core/object/script_language.h"
 #include "core/os/mutex.h"
 #include "core/os/mutex.h"
 #include "core/version.h"
 #include "core/version.h"
 
 
@@ -376,7 +377,12 @@ bool ClassDB::is_virtual(const StringName &p_class) {
 	OBJTYPE_RLOCK;
 	OBJTYPE_RLOCK;
 
 
 	ClassInfo *ti = classes.getptr(p_class);
 	ClassInfo *ti = classes.getptr(p_class);
-	ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'.");
+	if (!ti) {
+		if (!ScriptServer::is_global_class(p_class)) {
+			ERR_FAIL_V_MSG(false, "Cannot get class '" + String(p_class) + "'.");
+		}
+		return false;
+	}
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
 	if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) {
 	if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) {
 		return false;
 		return false;

+ 4 - 4
editor/create_dialog.cpp

@@ -284,12 +284,12 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const String
 	bool can_instantiate = (p_type_category == TypeCategory::CPP_TYPE && ClassDB::can_instantiate(p_type)) ||
 	bool can_instantiate = (p_type_category == TypeCategory::CPP_TYPE && ClassDB::can_instantiate(p_type)) ||
 			p_type_category == TypeCategory::OTHER_TYPE;
 			p_type_category == TypeCategory::OTHER_TYPE;
 
 
-	if (!can_instantiate) {
-		r_item->set_custom_color(0, search_options->get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
+	if (can_instantiate && !ClassDB::is_virtual(p_type)) {
+		r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback));
+	} else {
 		r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, "NodeDisabled"));
 		r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, "NodeDisabled"));
+		r_item->set_custom_color(0, search_options->get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
 		r_item->set_selectable(0, false);
 		r_item->set_selectable(0, false);
-	} else {
-		r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback));
 	}
 	}
 
 
 	bool is_deprecated = EditorHelp::get_doc_data()->class_list[p_type].is_deprecated;
 	bool is_deprecated = EditorHelp::get_doc_data()->class_list[p_type].is_deprecated;