diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 5030589f5d87..461958864388 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4847,6 +4847,19 @@ Ref EditorNode::_get_class_or_script_icon(const String &p_class, cons return theme->get_icon(p_class, EditorStringName(EditorIcons)); } + // If there is a path associated with the node but there was no icon there or it was invalid. + // Then it takes the basename of the file and, if it's the name of an icon in the theme, it uses that instead as a fallback. + // This enables using "Node2D" as a valid path to get the icon without having to copy it and have it inside the project folder. + if (GDExtensionManager::get_singleton()->class_has_icon_path(p_class)) { + String icon_name = GDExtensionManager::get_singleton() + ->class_get_icon_path(p_class) + .get_file() + .get_basename(); + if (theme->has_icon(icon_name, EditorStringName(EditorIcons))) { + return theme->get_icon(icon_name, EditorStringName(EditorIcons)); + } + } + if (!p_fallback.is_empty() && theme->has_icon(p_fallback, EditorStringName(EditorIcons))) { return theme->get_icon(p_fallback, EditorStringName(EditorIcons)); }