Editor: Fix display of objects in the Remote Inspector

This commit is contained in:
Danil Alexeev 2026-02-27 17:54:33 +03:00
parent f630133a01
commit f4b1d4b185
No known key found for this signature in database
GPG key ID: 5A52F75A8679EC57
3 changed files with 37 additions and 5 deletions

View file

@ -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<EncodedObjectAsID>(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<EncodedObjectAsID>(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));

View file

@ -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:

View file

@ -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