@@ -2416,22 +2416,39 @@ void EditorNode::edit_item(Object *p_object, Object *p_editing_owner) {
24162416 continue ;
24172417 }
24182418
2419+ bool need_to_add = true ;
2420+ List<EditorPropertyResource *> to_fold;
2421+
24192422 // If plugin is already associated with another owner, remove it from there first.
24202423 for (KeyValue<ObjectID, HashSet<EditorPlugin *>> &kv : active_plugins) {
2421- if (kv.key != owner_id) {
2422- EditorPropertyResource *epres = Object::cast_to<EditorPropertyResource>(ObjectDB::get_instance (kv.key ));
2423- if (epres && kv.value .has (plugin)) {
2424- // If it's resource property editing the same resource type, fold it.
2425- epres->fold_resource ();
2426- }
2424+ if (kv.key == owner_id || !kv.value .has (plugin)) {
2425+ continue ;
2426+ }
2427+ EditorPropertyResource *epres = Object::cast_to<EditorPropertyResource>(ObjectDB::get_instance (kv.key ));
2428+ if (epres) {
2429+ // If it's resource property editing the same resource type, fold it later to avoid premature modifications
2430+ // that may result in unsafe iteration of active_plugins.
2431+ to_fold.push_back (epres);
2432+ } else {
24272433 kv.value .erase (plugin);
2434+ need_to_add = false ;
2435+ }
2436+ }
2437+
2438+ if (!need_to_add && to_fold.is_empty ()) {
2439+ plugin->make_visible (true );
2440+ plugin->edit (p_object);
2441+ } else {
2442+ for (EditorPropertyResource *epres : to_fold) {
2443+ epres->fold_resource ();
24282444 }
2445+
2446+ // TODO: Call the function directly once a proper priority system is implemented.
2447+ to_over_edit.push_back (plugin);
24292448 }
24302449
24312450 // Activate previously inactive plugin and edit the object.
24322451 active_plugins[owner_id].insert (plugin);
2433- // TODO: Call the function directly once a proper priority system is implemented.
2434- to_over_edit.push_back (plugin);
24352452 }
24362453
24372454 for (EditorPlugin *plugin : to_over_edit) {
0 commit comments