@@ -2416,22 +2416,39 @@ void EditorNode::edit_item(Object *p_object, Object *p_editing_owner) {
2416
2416
continue ;
2417
2417
}
2418
2418
2419
+ bool need_to_add = true ;
2420
+ List<EditorPropertyResource *> to_fold;
2421
+
2419
2422
// If plugin is already associated with another owner, remove it from there first.
2420
2423
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 {
2427
2433
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 ();
2428
2444
}
2445
+
2446
+ // TODO: Call the function directly once a proper priority system is implemented.
2447
+ to_over_edit.push_back (plugin);
2429
2448
}
2430
2449
2431
2450
// Activate previously inactive plugin and edit the object.
2432
2451
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);
2435
2452
}
2436
2453
2437
2454
for (EditorPlugin *plugin : to_over_edit) {
0 commit comments