@@ -488,8 +488,8 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) {
488488 if (!base_type.is_empty ()) {
489489 int idx = 0 ;
490490
491- HashSet<StringName> allowed_types ;
492- _get_allowed_types ( false , & allowed_types) ;
491+ _ensure_allowed_types () ;
492+ HashSet<StringName> allowed_types = allowed_types_without_convert ;
493493
494494 for (const StringName &E : allowed_types) {
495495 const String &t = E;
@@ -593,23 +593,29 @@ static void _add_allowed_type(const StringName &p_type, HashSet<StringName> *p_v
593593 }
594594}
595595
596- void EditorResourcePicker::_get_allowed_types (bool p_with_convert, HashSet<StringName> *p_vector) const {
596+ void EditorResourcePicker::_ensure_allowed_types () const {
597+ if (!allowed_types_without_convert.is_empty ()) {
598+ return ;
599+ }
600+
597601 Vector<String> allowed_types = base_type.split (" ," );
598602 int size = allowed_types.size ();
599603
600604 for (int i = 0 ; i < size; i++) {
601- String base = allowed_types[i].strip_edges ();
605+ const String base = allowed_types[i].strip_edges ();
606+ _add_allowed_type (base, &allowed_types_without_convert);
607+ }
602608
603- _add_allowed_type (base, p_vector );
609+ allowed_types_with_convert = HashSet<StringName>(allowed_types_without_convert );
604610
605- if (p_with_convert ) {
606- if ( base == " BaseMaterial3D " ) {
607- p_vector-> insert ( " Texture2D " );
608- } else if (base == " ShaderMaterial " ) {
609- p_vector-> insert ( " Shader " );
610- } else if (base == " Texture2D " ) {
611- p_vector-> insert ( " Image " );
612- }
611+ for ( int i = 0 ; i < size; i++ ) {
612+ const String base = allowed_types[i]. strip_edges ();
613+ if (base == " BaseMaterial3D " ) {
614+ allowed_types_with_convert. insert ( " Texture2D " );
615+ } else if (base == " ShaderMaterial " ) {
616+ allowed_types_with_convert. insert ( " Shader " );
617+ } else if (base == " Texture2D " ) {
618+ allowed_types_with_convert. insert ( " Image " );
613619 }
614620 }
615621}
@@ -645,8 +651,8 @@ bool EditorResourcePicker::_is_drop_valid(const Dictionary &p_drag_data) const {
645651 }
646652 }
647653
648- HashSet<StringName> allowed_types ;
649- _get_allowed_types ( true , & allowed_types) ;
654+ _ensure_allowed_types () ;
655+ HashSet<StringName> allowed_types = allowed_types_with_convert ;
650656
651657 if (res.is_valid ()) {
652658 String res_type = _get_resource_type (res);
@@ -713,8 +719,8 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
713719 }
714720
715721 if (dropped_resource.is_valid ()) {
716- HashSet<StringName> allowed_types ;
717- _get_allowed_types ( false , & allowed_types) ;
722+ _ensure_allowed_types () ;
723+ HashSet<StringName> allowed_types = allowed_types_without_convert ;
718724
719725 String res_type = _get_resource_type (dropped_resource);
720726
@@ -835,8 +841,8 @@ void EditorResourcePicker::set_base_type(const String &p_base_type) {
835841 // There is a possibility that the new base type is conflicting with the existing value.
836842 // Keep the value, but warn the user that there is a potential mistake.
837843 if (!base_type.is_empty () && edited_resource.is_valid ()) {
838- HashSet<StringName> allowed_types ;
839- _get_allowed_types ( true , & allowed_types) ;
844+ _ensure_allowed_types () ;
845+ HashSet<StringName> allowed_types = allowed_types_with_convert ;
840846
841847 StringName custom_class;
842848 bool is_custom = false ;
@@ -857,8 +863,8 @@ String EditorResourcePicker::get_base_type() const {
857863}
858864
859865Vector<String> EditorResourcePicker::get_allowed_types () const {
860- HashSet<StringName> allowed_types ;
861- _get_allowed_types ( false , & allowed_types) ;
866+ _ensure_allowed_types () ;
867+ HashSet<StringName> allowed_types = allowed_types_without_convert ;
862868
863869 Vector<String> types;
864870 types.resize (allowed_types.size ());
@@ -881,8 +887,8 @@ void EditorResourcePicker::set_edited_resource(Ref<Resource> p_resource) {
881887 }
882888
883889 if (!base_type.is_empty ()) {
884- HashSet<StringName> allowed_types ;
885- _get_allowed_types ( true , & allowed_types) ;
890+ _ensure_allowed_types () ;
891+ HashSet<StringName> allowed_types = allowed_types_with_convert ;
886892
887893 StringName custom_class;
888894 bool is_custom = false ;
0 commit comments