diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index eab1ecf373dd..e76f5264d3f0 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -899,17 +899,11 @@ String EditorData::script_class_get_icon_path(const String &p_class) const { return String(); } - String current = p_class; - String ret = _script_class_icon_paths[current]; - while (ret.empty()) { - current = script_class_get_base(current); - if (!ScriptServer::is_global_class(current)) { - return String(); - } - ret = _script_class_icon_paths.has(current) ? _script_class_icon_paths[current] : String(); + if (_script_class_icon_paths.has(p_class)) { + return _script_class_icon_paths[p_class]; } - return ret; + return script_class_get_icon_path(script_class_get_base(p_class)); } StringName EditorData::script_class_get_name(const String &p_path) const { @@ -950,8 +944,8 @@ void EditorData::script_class_load_icon_paths() { d.get_key_list(&keys); for (List::Element *E = keys.front(); E; E = E->next()) { - String name = E->get().operator String(); - _script_class_icon_paths[name] = d[name]; + String name = (String)E->get(); + _script_class_icon_paths[name] = d.has(name) ? String(d[name]) : String(); String path = ScriptServer::get_global_class_path(name); script_class_set_name(path, name); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index a8dc14427d08..1ebdd0320ffc 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3760,21 +3760,32 @@ StringName EditorNode::get_object_custom_type_name(const Object *p_object) const return StringName(); } -Ref EditorNode::_load_custom_class_icon(const String &p_path) const { - if (p_path.length()) { - Ref img = memnew(Image); - Error err = ImageLoader::load_image(p_path, img); - if (err == OK) { - Ref icon = memnew(ImageTexture); - img->resize(16 * EDSCALE, 16 * EDSCALE, Image::INTERPOLATE_LANCZOS); - icon->create_from_image(img); - return icon; +Ref EditorNode::_load_custom_class_icon(const String &p_path) { + if (p_path.length() && p_path != "Null") { + Error err; + RES res = ResourceLoader::load(p_path, "", false, &err); + if (Object::cast_to(*res)) { + res = ((Texture2D*)(*res))->get_data(); + ERR_FAIL_COND_V(err != OK, nullptr); + } else if (Object::cast_to(*res)) { + res = ResourceLoader::load(p_path, "", false, &err); + ERR_FAIL_COND_V(err != OK, nullptr); + } else { + ERR_FAIL_V_MSG(nullptr, "Icon is neither an Image nor a Texture"); } + + Ref img = res; + + img->resize(16 * EDSCALE, 16 * EDSCALE, Image::INTERPOLATE_LANCZOS); + + Ref icon = memnew(ImageTexture); + icon->create_from_image(img); + return icon; } return nullptr; } -Ref EditorNode::get_object_icon(const Object *p_object, const String &p_fallback) const { +Ref EditorNode::get_object_icon(const Object *p_object, const String &p_fallback) { ERR_FAIL_COND_V(!p_object || !gui_base, nullptr); Ref