diff --git a/NEWS.md b/NEWS.md index fc1f6f5f49..533ac6a51a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,6 +17,7 @@ * Scripting: Made Tileset.margin and Tileset.tileSpacing writable * Scripting: Restored compatibility for MapObject.polygon (#3845) * Scripting: Fixed issues with editing properties after setting class values from script +* Scripting: Fixed setting/getting object reference values when nested as a class member * TMX format: Embedded images are now also supported on tilesets and image layers * JSON format: Fixed tile order when loading a tileset using the old format * Godot 4 plugin: Added support for exporting objects (by Rick Yorgason, #3615) diff --git a/src/tiled/editableobject.cpp b/src/tiled/editableobject.cpp index 449bd5659d..166ceee7dd 100644 --- a/src/tiled/editableobject.cpp +++ b/src/tiled/editableobject.cpp @@ -193,17 +193,31 @@ QVariant EditableObject::toScript(const QVariant &value) const } } + if (type == propertyValueId()) { + auto propertyValue = value.value(); + propertyValue.value = toScript(propertyValue.value); + return QVariant::fromValue(propertyValue); + } + return value; } QVariant EditableObject::fromScript(const QVariant &value) const { - if (value.userType() == QMetaType::QVariantMap) + const int type = value.userType(); + + if (type == QMetaType::QVariantMap) return fromScript(value.toMap()); if (auto editableMapObject = value.value()) return QVariant::fromValue(ObjectRef { editableMapObject->id() }); + if (type == propertyValueId()) { + auto propertyValue = value.value(); + propertyValue.value = fromScript(propertyValue.value); + return QVariant::fromValue(propertyValue); + } + return value; }