Skip to content

Commit 18b2506

Browse files
author
Roberto De Ioris
committed
preliminary support for new 4.15 properties
1 parent 94a98af commit 18b2506

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ void ue_pydelegates_cleanup(ue_PyUObject *self) {
600600
UE_LOG(LogPython, Warning, TEXT("Removing UPythonDelegate %p from ue_PyUObject %p mapped to UObject %p"), py_delegate, self, self->ue_object);
601601
#endif
602602
py_delegate->RemoveFromRoot();
603-
}
603+
}
604604
}
605605
self->python_delegates_gc->clear();
606606
delete self->python_delegates_gc;
@@ -1290,7 +1290,7 @@ void unreal_engine_py_log_error() {
12901290
}
12911291

12921292
PyErr_Clear();
1293-
}
1293+
}
12941294

12951295
// retrieve a UWorld from a generic UObject (if possible)
12961296
UWorld *ue_get_uworld(ue_PyUObject *py_obj) {
@@ -1342,11 +1342,21 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer) {
13421342
return PyLong_FromLong(value);
13431343
}
13441344

1345+
if (auto casted_prop = Cast<UUInt32Property>(prop)) {
1346+
uint32 value = casted_prop->GetPropertyValue_InContainer(buffer);
1347+
return PyLong_FromUnsignedLong(value);
1348+
}
1349+
13451350
if (auto casted_prop = Cast<UInt64Property>(prop)) {
13461351
long long value = casted_prop->GetPropertyValue_InContainer(buffer);
13471352
return PyLong_FromLongLong(value);
13481353
}
13491354

1355+
if (auto casted_prop = Cast<UUInt64Property>(prop)) {
1356+
uint64 value = casted_prop->GetPropertyValue_InContainer(buffer);
1357+
return PyLong_FromUnsignedLongLong(value);
1358+
}
1359+
13501360
if (auto casted_prop = Cast<UFloatProperty>(prop)) {
13511361
float value = casted_prop->GetPropertyValue_InContainer(buffer);
13521362
return PyFloat_FromDouble(value);
@@ -1357,6 +1367,14 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer) {
13571367
return PyLong_FromLong(value);
13581368
}
13591369

1370+
#if ENGINE_MINOR_VERSION >= 15
1371+
if (auto casted_prop = Cast<UEnumProperty>(prop)) {
1372+
UEnum *value = casted_prop->GetEnum();
1373+
uint64 enum_index = casted_prop->GetUnderlyingProperty()->GetUnsignedIntPropertyValue(buffer);
1374+
return PyLong_FromUnsignedLong(enum_index);
1375+
}
1376+
#endif
1377+
13601378
if (auto casted_prop = Cast<UStrProperty>(prop)) {
13611379
FString value = casted_prop->GetPropertyValue_InContainer(buffer);
13621380
return PyUnicode_FromString(TCHAR_TO_UTF8(*value));
@@ -1471,6 +1489,41 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer) {
14711489
return py_list;
14721490
}
14731491

1492+
#if ENGINE_MINOR_VERSION >= 15
1493+
if (auto casted_prop = Cast<UMapProperty>(prop)) {
1494+
FScriptMapHelper_InContainer map_helper(casted_prop, buffer);
1495+
1496+
PyObject *py_dict = PyDict_New();
1497+
1498+
int32 num = map_helper.Num();
1499+
for (int32 i = 0; num; i++) {
1500+
if (map_helper.IsValidIndex(i)) {
1501+
num--;
1502+
1503+
uint8 *key = map_helper.GetKeyPtr(i);
1504+
PyObject *py_key = ue_py_convert_property(map_helper.KeyProp, key);
1505+
if (!py_key) {
1506+
Py_DECREF(py_dict);
1507+
return NULL;
1508+
}
1509+
1510+
uint8 *value = map_helper.GetValuePtr(i);
1511+
PyObject *py_value = ue_py_convert_property(map_helper.ValueProp, value);
1512+
if (!py_value) {
1513+
Py_DECREF(py_dict);
1514+
return NULL;
1515+
}
1516+
1517+
PyDict_SetItem(py_dict, py_key, py_value);
1518+
Py_DECREF(py_key);
1519+
Py_DECREF(py_value);
1520+
}
1521+
}
1522+
1523+
return py_dict;
1524+
}
1525+
#endif
1526+
14741527
return PyErr_Format(PyExc_Exception, "unsupported value type %s for property %s", TCHAR_TO_UTF8(*prop->GetClass()->GetName()), TCHAR_TO_UTF8(*prop->GetName()));
14751528
}
14761529

0 commit comments

Comments
 (0)