Skip to content

Commit 0496152

Browse files
author
Roberto De Ioris
committed
improved enum support
1 parent 3223dfc commit 0496152

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,14 +1598,14 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer) {
15981598
}
15991599

16001600
if (auto casted_prop = Cast<UByteProperty>(prop)) {
1601-
int8 value = casted_prop->GetPropertyValue_InContainer(buffer);
1601+
uint8 value = casted_prop->GetPropertyValue_InContainer(buffer);
16021602
return PyLong_FromUnsignedLong(value);
16031603
}
16041604

16051605
#if ENGINE_MINOR_VERSION >= 15
16061606
if (auto casted_prop = Cast<UEnumProperty>(prop)) {
1607-
UEnum *value = casted_prop->GetEnum();
1608-
uint64 enum_index = casted_prop->GetUnderlyingProperty()->GetUnsignedIntPropertyValue(buffer);
1607+
void *prop_addr = casted_prop->ContainerPtrToValuePtr<void>(buffer);
1608+
uint64 enum_index = casted_prop->GetUnderlyingProperty()->GetUnsignedIntPropertyValue(prop_addr);
16091609
return PyLong_FromUnsignedLong(enum_index);
16101610
}
16111611
#endif
@@ -1807,10 +1807,21 @@ bool ue_py_convert_pyobject(PyObject *py_obj, UProperty *prop, uint8 *buffer) {
18071807
}
18081808
if (auto casted_prop = Cast<UByteProperty>(prop)) {
18091809
PyObject *py_long = PyNumber_Long(py_obj);
1810-
casted_prop->SetPropertyValue_InContainer(buffer, PyLong_AsLong(py_long));
1810+
casted_prop->SetPropertyValue_InContainer(buffer, PyLong_AsUnsignedLong(py_long));
18111811
Py_DECREF(py_long);
18121812
return true;
18131813
}
1814+
#if ENGINE_MINOR_VERSION >= 15
1815+
if (auto casted_prop = Cast<UEnumProperty>(prop)) {
1816+
PyObject *py_long = PyNumber_Long(py_obj);
1817+
void *prop_addr = casted_prop->ContainerPtrToValuePtr<void>(buffer);
1818+
casted_prop->GetUnderlyingProperty()->SetIntPropertyValue(prop_addr, (uint64)PyLong_AsUnsignedLong(py_long));
1819+
Py_DECREF(py_long);
1820+
return true;
1821+
}
1822+
#endif
1823+
1824+
18141825
return false;
18151826
}
18161827

0 commit comments

Comments
 (0)