From f4b1d4b1857a4f0d4ce9e9b9dcbf58238bac8c03 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Fri, 27 Feb 2026 17:54:33 +0300 Subject: [PATCH] Editor: Fix display of objects in the Remote Inspector --- editor/inspector/editor_properties.cpp | 35 ++++++++++++++++++++---- editor/inspector/editor_properties.h | 3 ++ scene/debugger/scene_debugger_object.cpp | 4 +++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/editor/inspector/editor_properties.cpp b/editor/inspector/editor_properties.cpp index 27edf0e84a..dbecd63813 100644 --- a/editor/inspector/editor_properties.cpp +++ b/editor/inspector/editor_properties.cpp @@ -32,6 +32,7 @@ #include "core/config/project_settings.h" #include "core/input/input_map.h" +#include "core/io/marshalls.h" #include "core/object/class_db.h" #include "core/string/translation_server.h" #include "editor/docks/inspector_dock.h" @@ -97,6 +98,10 @@ void EditorPropertyVariant::_popup_edit_menu() { change_type->popup(); } +void EditorPropertyVariant::_object_id_selected(const StringName &p_property, ObjectID p_id) { + emit_signal(SNAME("object_id_selected"), p_property, p_id); +} + void EditorPropertyVariant::_set_read_only(bool p_read_only) { edit_button->set_disabled(p_read_only); if (sub_property) { @@ -125,7 +130,14 @@ void EditorPropertyVariant::update_property() { } if (current_type == Variant::OBJECT) { - sub_property = EditorInspector::instantiate_property_editor(nullptr, current_type, "", PROPERTY_HINT_RESOURCE_TYPE, Resource::get_class_static(), PROPERTY_USAGE_NONE); + Object *obj = value.get_validated_object(); + if (Object::cast_to(obj)) { + EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID); + editor->setup("Object"); + sub_property = editor; + } else { + sub_property = EditorInspector::instantiate_property_editor(nullptr, current_type, "", PROPERTY_HINT_RESOURCE_TYPE, Resource::get_class_static(), PROPERTY_USAGE_NONE); + } } else { sub_property = EditorInspector::instantiate_property_editor(nullptr, current_type, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE); } @@ -138,6 +150,7 @@ void EditorPropertyVariant::update_property() { sub_property->set_read_only(is_read_only()); sub_property->set_h_size_flags(SIZE_EXPAND_FILL); sub_property->connect(SNAME("property_changed"), callable_mp((EditorProperty *)this, &EditorProperty::emit_changed)); + sub_property->connect(SNAME("object_id_selected"), callable_mp(this, &EditorPropertyVariant::_object_id_selected)); content->add_child(sub_property); content->move_child(sub_property, 0); sub_property->update_property(); @@ -1604,12 +1617,24 @@ EditorPropertyInteger::EditorPropertyInteger() { ///////////////////// OBJECT ID ///////////////////////// -void EditorPropertyObjectID::_set_read_only(bool p_read_only) { - edit->set_disabled(p_read_only); +ObjectID EditorPropertyObjectID::_get_object_id() const { + const Variant value = get_edited_property_value(); + if (value.get_type() == Variant::OBJECT) { + Object *obj = value.get_validated_object(); + EncodedObjectAsID *obj_as_id = Object::cast_to(obj); + if (obj_as_id) { + return obj_as_id->get_object_id(); + } + } + return value; } void EditorPropertyObjectID::_edit_pressed() { - emit_signal(SNAME("object_id_selected"), get_edited_property(), get_edited_property_value()); + emit_signal(SNAME("object_id_selected"), get_edited_property(), _get_object_id()); +} + +void EditorPropertyObjectID::_set_read_only(bool p_read_only) { + edit->set_disabled(p_read_only); } void EditorPropertyObjectID::update_property() { @@ -1618,7 +1643,7 @@ void EditorPropertyObjectID::update_property() { type = "Object"; } - ObjectID id = get_edited_property_value(); + ObjectID id = _get_object_id(); if (id.is_valid()) { edit->set_text(type + " ID: " + uitos(id)); edit->set_tooltip_text(type + " ID: " + uitos(id)); diff --git a/editor/inspector/editor_properties.h b/editor/inspector/editor_properties.h index 62c818b1d3..8930d33509 100644 --- a/editor/inspector/editor_properties.h +++ b/editor/inspector/editor_properties.h @@ -81,6 +81,7 @@ class EditorPropertyVariant : public EditorProperty { void _change_type(int p_to_type); void _popup_edit_menu(); + void _object_id_selected(const StringName &p_property, ObjectID p_id); protected: virtual void _set_read_only(bool p_read_only) override; @@ -414,6 +415,8 @@ class EditorPropertyObjectID : public EditorProperty { GDCLASS(EditorPropertyObjectID, EditorProperty); Button *edit = nullptr; String base_type; + + ObjectID _get_object_id() const; void _edit_pressed(); protected: diff --git a/scene/debugger/scene_debugger_object.cpp b/scene/debugger/scene_debugger_object.cpp index 44ddc0777c..4ffaca24bf 100644 --- a/scene/debugger/scene_debugger_object.cpp +++ b/scene/debugger/scene_debugger_object.cpp @@ -181,6 +181,10 @@ void SceneDebuggerObject::serialize(Array &r_arr, int p_max_size) { PropertyHint hint = pi.hint; String hint_string = pi.hint_string; if (res.is_valid() && !res->get_path().is_empty()) { + // HACK: Overwrite `PropertyInfo` with the current runtime type. + // This allows untyped variables to be displayed correctly. + prop[1] = Variant::OBJECT; + var = res->get_path(); } else { //only send information that can be sent.. int len = 0; //test how big is this to encode