Godot Engine – Multi-platform 2D and 3D game engine
Use ObjectID in Connections and Inspector docks
kit0864cc9df4f8
diff --git a/editor/inspector/editor_inspector.cpp b/editor/inspector/editor_inspector.cppindex 92fd2dd633d..a3454f189bf 100644--- a/editor/inspector/editor_inspector.cpp+++ b/editor/inspector/editor_inspector.cpp@@ -103,6 +103,8 @@ bool EditorInspector::_resource_properties_matches(const Ref<Resource> &p_resourString subgroup;String subgroup_base;+ Object *object = ObjectDB::get_instance(edited_object_id);+List<PropertyInfo> plist;p_resource->get_property_list(&plist, true);@@ -4291,6 +4293,7 @@ void EditorInspector::_update_property_editor(EditorProperty *p_ep) {}void EditorInspector::_parse_added_editors(VBoxContainer *p_current_vbox, EditorInspectorSection *p_section, Ref<EditorInspectorPlugin> p_plugin) {+ Object *object = ObjectDB::get_instance(edited_object_id);for (const EditorInspectorPlugin::AddedEditor &F : p_plugin->added_editors) {EditorProperty *ep = Object::cast_to<EditorProperty>(F.property_editor);@@ -4351,6 +4354,7 @@ bool EditorInspector::_is_property_disabled_by_feature_profile(const StringNamereturn false;}+ Object *object = ObjectDB::get_instance(edited_object_id);StringName class_name = object->get_class();while (class_name != StringName()) {@@ -4383,6 +4387,7 @@ void EditorInspector::_add_section_in_tree(EditorInspectorSection *p_section, VB}void EditorInspector::update_tree() {+ Object *object = ObjectDB::get_instance(edited_object_id);if (!object) {return;}@@ -5437,6 +5442,7 @@ void EditorInspector::_clear(bool p_hide_plugins) {}Object *EditorInspector::get_edited_object() {+ Object *object = ObjectDB::get_instance(edited_object_id);return object;}@@ -5445,25 +5451,25 @@ Object *EditorInspector::get_next_edited_object() {}void EditorInspector::edit(Object *p_object) {+ Object *object = ObjectDB::get_instance(edited_object_id);if (object == p_object) {return;}next_object = p_object; // Some plugins need to know the next edited object when clearing the inspector.if (object) {- if (likely(Variant(object).get_validated_object())) {- object->disconnect(CoreStringName(property_list_changed), callable_mp(this, &EditorInspector::_changed_callback));- }+ object->disconnect(CoreStringName(property_list_changed), callable_mp(this, &EditorInspector::_changed_callback));_clear();}per_array_page.clear();+ edited_object_id = p_object ? p_object->get_instance_id() : ObjectID();object = p_object;if (object) {update_scroll_request = 0; //reset- if (scroll_cache.has(object->get_instance_id())) { //if exists, set something else- update_scroll_request = scroll_cache[object->get_instance_id()]; //done this way because wait until full size is accommodated+ if (scroll_cache.has(edited_object_id)) { // If exists, set something else.+ update_scroll_request = scroll_cache[edited_object_id]; // Done this way because wait until full size is accommodated.}object->connect(CoreStringName(property_list_changed), callable_mp(this, &EditorInspector::_changed_callback));@@ -5685,6 +5691,7 @@ void EditorInspector::_page_change_request(int p_new_page, const StringName &p_a}void EditorInspector::_edit_request_change(Object *p_object, const String &p_property) {+ Object *object = ObjectDB::get_instance(edited_object_id);if (object != p_object) { //may be undoing/redoing for a non edited object, so ignorereturn;}@@ -5709,6 +5716,7 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo}}+ Object *object = ObjectDB::get_instance(edited_object_id);EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();if (!undo_redo || bool(object->call(SNAME("_dont_undo_redo")))) {object->set(p_name, p_value);@@ -5879,6 +5887,7 @@ void EditorInspector::_multiple_properties_changed(const Vector<String> &p_paths}void EditorInspector::_property_keyed(const String &p_path, bool p_advance) {+ Object *object = ObjectDB::get_instance(edited_object_id);if (!object) {return;}@@ -5890,6 +5899,7 @@ void EditorInspector::_property_keyed(const String &p_path, bool p_advance) {}void EditorInspector::_property_deleted(const String &p_path) {+ Object *object = ObjectDB::get_instance(edited_object_id);if (!object) {return;}@@ -5910,6 +5920,7 @@ void EditorInspector::_property_deleted(const String &p_path) {}void EditorInspector::_property_keyed_with_value(const String &p_path, const Variant &p_value, bool p_advance) {+ Object *object = ObjectDB::get_instance(edited_object_id);if (!object) {return;}@@ -5921,6 +5932,7 @@ void EditorInspector::_property_keyed_with_value(const String &p_path, const Var}void EditorInspector::_property_checked(const String &p_path, bool p_checked) {+ Object *object = ObjectDB::get_instance(edited_object_id);if (!object) {return;}@@ -5962,6 +5974,7 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) {}void EditorInspector::_property_pinned(const String &p_path, bool p_pinned) {+ Object *object = ObjectDB::get_instance(edited_object_id);if (!object) {return;}@@ -6009,6 +6022,7 @@ void EditorInspector::_resource_selected(const String &p_path, Ref<Resource> p_r}void EditorInspector::_node_removed(Node *p_node) {+ Object *object = ObjectDB::get_instance(edited_object_id);if (p_node == object) {edit(nullptr);}@@ -6023,6 +6037,7 @@ void EditorInspector::_update_current_favorites() {HashMap<String, PackedStringArray> favorites = EditorSettings::get_singleton()->get_favorite_properties();// Fetch script properties.+ Object *object = ObjectDB::get_instance(edited_object_id);Ref<Script> scr = object->get_script();if (scr.is_valid()) {List<PropertyInfo> plist;@@ -6078,6 +6093,7 @@ void EditorInspector::_update_current_favorites() {}void EditorInspector::_set_property_favorited(const String &p_path, bool p_favorited) {+ Object *object = ObjectDB::get_instance(edited_object_id);if (!object) {return;}@@ -6167,6 +6183,7 @@ void EditorInspector::_clear_current_favorites() {HashMap<String, PackedStringArray> favorites = EditorSettings::get_singleton()->get_favorite_properties();+ Object *object = ObjectDB::get_instance(edited_object_id);Ref<Script> scr = object->get_script();if (scr.is_valid()) {List<PropertyInfo> plist;@@ -6303,6 +6320,7 @@ void EditorInspector::_notification(int p_what) {void EditorInspector::_changed_callback() {//this is called when property change is notified via notify_property_list_changed()+ Object *object = ObjectDB::get_instance(edited_object_id);if (object != nullptr) {_update_current_favorites();_edit_request_change(object, String());@@ -6314,8 +6332,8 @@ void EditorInspector::_vscroll_changed(double p_offset) {return;}- if (object) {- scroll_cache[object->get_instance_id()] = p_offset;+ if (edited_object_id.is_valid()) {+ scroll_cache[edited_object_id] = p_offset;}}@@ -6387,6 +6405,7 @@ void EditorInspector::_show_add_meta_dialog() {}StringName dialog_title;+ Object *object = ObjectDB::get_instance(edited_object_id);Node *node = Object::cast_to<Node>(object);// If object is derived from Node use node name, if derived from Resource use classname.dialog_title = node ? node->get_name() : StringName(object->get_class());@@ -6397,6 +6416,7 @@ void EditorInspector::_show_add_meta_dialog() {}void EditorInspector::_add_meta_confirm() {+ Object *object = ObjectDB::get_instance(edited_object_id);// Ensure metadata is unfolded when adding a new metadata.object->editor_set_section_unfold("metadata", true);diff --git a/editor/inspector/editor_inspector.h b/editor/inspector/editor_inspector.hindex ef771b4c6f5..52507955438 100644--- a/editor/inspector/editor_inspector.h+++ b/editor/inspector/editor_inspector.h@@ -805,7 +805,7 @@ private:HashSet<StringName> pending;void _clear(bool p_hide_plugins = true);- Object *object = nullptr;+ ObjectID edited_object_id;Object *next_object = nullptr;//diff --git a/editor/scene/connections_dialog.cpp b/editor/scene/connections_dialog.cppindex 1da6444ed0c..c059d3c2996 100644--- a/editor/scene/connections_dialog.cpp+++ b/editor/scene/connections_dialog.cpp@@ -987,6 +987,7 @@ void ConnectionsDock::_filter_changed(const String &p_text) {*/void ConnectionsDock::_make_or_edit_connection() {NodePath dst_path = connect_dialog->get_dst_path();+ Object *selected_object = ObjectDB::get_instance(selected_object_id);Node *target = Object::cast_to<Node>(selected_object)->get_node(dst_path);ERR_FAIL_NULL(target);@@ -1121,6 +1122,7 @@ void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {* Break single connection w/ undo-redo functionality.*/void ConnectionsDock::_disconnect(const ConnectDialog::ConnectionData &p_cd) {+ Object *selected_object = ObjectDB::get_instance(selected_object_id);ERR_FAIL_COND(p_cd.source != selected_object); // Shouldn't happen but... Bugcheck.EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();@@ -1156,6 +1158,7 @@ void ConnectionsDock::_disconnect_all() {Connection connection = child->get_metadata(0);if (!_is_connection_inherited(connection)) {ConnectDialog::ConnectionData cd = connection;+ Object *selected_object = ObjectDB::get_instance(selected_object_id);undo_redo->add_do_method(selected_object, "disconnect", cd.signal, cd.get_callable());undo_redo->add_undo_method(selected_object, "connect", cd.signal, cd.get_callable(), cd.flags);}@@ -1232,6 +1235,7 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {ConnectDialog::ConnectionData cd;+ Object *selected_object = ObjectDB::get_instance(selected_object_id);Node *selected_node = Object::cast_to<Node>(selected_object);Node *dst_node = selected_node->get_owner() ? selected_node->get_owner() : selected_node;if (!dst_node || dst_node->get_script().is_null()) {@@ -1279,6 +1283,7 @@ void ConnectionsDock::_go_to_method(TreeItem &p_item) {Connection connection = p_item.get_metadata(0);ConnectDialog::ConnectionData cd = connection;+ Object *selected_object = ObjectDB::get_instance(selected_object_id);ERR_FAIL_COND(cd.source != selected_object); // Shouldn't happen but... bugcheck.if (!cd.target) {@@ -1470,6 +1475,7 @@ void ConnectionsDock::_close() {}void ConnectionsDock::_changed_callback() {+ Object *selected_object = ObjectDB::get_instance(selected_object_id);if (selected_object != nullptr) {update_tree();}@@ -1532,10 +1538,13 @@ void ConnectionsDock::set_object(Object *p_object) {select_an_object->hide();holder->show();}- if (selected_object != nullptr && likely(Variant(selected_object).get_validated_object())) {++ Object *selected_object = ObjectDB::get_instance(selected_object_id);+ if (selected_object != nullptr) {selected_object->disconnect(CoreStringName(property_list_changed), callable_mp(this, &ConnectionsDock::_changed_callback));}+ selected_object_id = p_object ? p_object->get_instance_id() : ObjectID();selected_object = p_object;is_editing_resource = (Object::cast_to<Resource>(selected_object) != nullptr);@@ -1552,6 +1561,7 @@ void ConnectionsDock::update_tree() {}tree->clear();+ Object *selected_object = ObjectDB::get_instance(selected_object_id);if (!selected_object) {return;}diff --git a/editor/scene/connections_dialog.h b/editor/scene/connections_dialog.hindex dc12996d0c2..e9d89301f85 100644--- a/editor/scene/connections_dialog.h+++ b/editor/scene/connections_dialog.h@@ -235,7 +235,7 @@ class ConnectionsDock : public VBoxContainer {VBoxContainer *holder = nullptr;Label *select_an_object = nullptr;- Object *selected_object = nullptr;+ ObjectID selected_object_id;ConnectionsDockTree *tree = nullptr;ConfirmationDialog *disconnect_all_dialog = nullptr;