Skip to content

Commit ded156b

Browse files
author
Roberto De Ioris
committed
added get_property_struct()
1 parent e08da0f commit ded156b

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
348348
{ "get_property_class", (PyCFunction)py_ue_get_property_class, METH_VARARGS, "" },
349349
{ "has_property", (PyCFunction)py_ue_has_property, METH_VARARGS, "" },
350350
{ "get_uproperty", (PyCFunction)py_ue_get_uproperty, METH_VARARGS, "" },
351+
{ "get_property_struct", (PyCFunction)py_ue_get_property_struct, METH_VARARGS, "" },
351352

352353
{ "functions", (PyCFunction)py_ue_functions, METH_VARARGS, "" },
353354

Source/UnrealEnginePython/Private/UEPyObject.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@ PyObject *py_ue_get_class(ue_PyUObject * self, PyObject * args) {
1919
return (PyObject *)ret;
2020
}
2121

22+
PyObject *py_ue_get_property_struct(ue_PyUObject * self, PyObject * args) {
23+
24+
ue_py_check(self);
25+
26+
char *property_name;
27+
if (!PyArg_ParseTuple(args, "s:get_property_struct", &property_name)) {
28+
return NULL;
29+
}
30+
31+
UStruct *u_struct = nullptr;
32+
33+
if (self->ue_object->IsA<UClass>()) {
34+
u_struct = (UStruct *)self->ue_object;
35+
}
36+
else {
37+
u_struct = (UStruct *)self->ue_object->GetClass();
38+
}
39+
40+
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
41+
if (!u_property)
42+
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
43+
44+
UStructProperty *prop = Cast<UStructProperty>(u_property);
45+
if (!prop)
46+
return PyErr_Format(PyExc_Exception, "object is not a StructProperty");
47+
return py_ue_new_uscriptstruct(prop->Struct, prop->ContainerPtrToValuePtr<uint8>(self->ue_object));
48+
}
49+
2250
PyObject *py_ue_get_super_class(ue_PyUObject * self, PyObject * args) {
2351

2452
ue_py_check(self);

Source/UnrealEnginePython/Private/UEPyObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PyObject *py_ue_set_name(ue_PyUObject *, PyObject * args);
1414
PyObject *py_ue_get_full_name(ue_PyUObject *, PyObject *);
1515
PyObject *py_ue_get_path_name(ue_PyUObject *, PyObject *);
1616
PyObject *py_ue_set_property(ue_PyUObject *, PyObject *);
17+
PyObject *py_ue_get_property_struct(ue_PyUObject *, PyObject *);
1718
PyObject *py_ue_properties(ue_PyUObject *, PyObject *);
1819
PyObject *py_ue_call(ue_PyUObject *, PyObject *);
1920
PyObject *py_ue_get_property(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)