Skip to content

Commit 166619c

Browse files
author
Roberto De Ioris
committed
added support for struct in native subclassing api
1 parent 2e85560 commit 166619c

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Editor/StaticMeshEditor/Public/StaticMeshEditorModule.h"
1010
#include "Editor/PropertyEditor/Public/PropertyEditorModule.h"
1111
#include "Editor/PropertyEditor/Public/ISinglePropertyView.h"
12+
#include "Editor/PropertyEditor/Public/IDetailsView.h"
1213
#endif
1314

1415
#include "Runtime/Slate/Public/Framework/Commands/UICommandList.h"
@@ -727,6 +728,7 @@ PyObject *py_unreal_engine_create_detail_view(PyObject *self, PyObject * args, P
727728
FPropertyEditorModule& PropertyEditorModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
728729
FDetailsViewArgs view_args;
729730
view_args.bAllowSearch = (py_allow_search && PyObject_IsTrue(py_allow_search));
731+
view_args.NameAreaSettings = FDetailsViewArgs::ENameAreaSettings::HideNameArea;
730732

731733
TSharedPtr<IDetailsView> view = PropertyEditorModule.CreateDetailView(view_args);
732734
view->SetObject(u_object);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,15 @@ static int unreal_engine_py_init(ue_PyUObject *self, PyObject *args, PyObject *k
11611161
prop_added = true;
11621162
}
11631163
}
1164+
else if (py_obj->ue_object->IsA<UScriptStruct>()) {
1165+
if (!py_ue_add_property(self, Py_BuildValue("(OsO)", (PyObject *)ue_get_python_wrapper(UStructProperty::StaticClass()), class_key, value))) {
1166+
unreal_engine_py_log_error();
1167+
return -1;
1168+
}
1169+
prop_added = true;
1170+
}
11641171
}
1172+
11651173
// add array property
11661174
else if (PyList_Check(value)) {
11671175
if (PyList_Size(value) == 1) {
@@ -1177,6 +1185,7 @@ static int unreal_engine_py_init(ue_PyUObject *self, PyObject *args, PyObject *k
11771185
}
11781186
prop_added = true;
11791187
}
1188+
11801189
else {
11811190
if (!py_ue_add_property(self, Py_BuildValue("([O]sO)", (PyObject *)ue_get_python_wrapper(UObjectProperty::StaticClass()), class_key, first_item))) {
11821191
unreal_engine_py_log_error();
@@ -1185,7 +1194,15 @@ static int unreal_engine_py_init(ue_PyUObject *self, PyObject *args, PyObject *k
11851194
prop_added = true;
11861195
}
11871196
}
1197+
else if (py_obj->ue_object->IsA<UScriptStruct>()) {
1198+
if (!py_ue_add_property(self, Py_BuildValue("([O]sO)", (PyObject *)ue_get_python_wrapper(UStructProperty::StaticClass()), class_key, first_item))) {
1199+
unreal_engine_py_log_error();
1200+
return -1;
1201+
}
1202+
prop_added = true;
1203+
}
11881204
}
1205+
11891206
}
11901207
}
11911208
// function ?
@@ -1547,7 +1564,7 @@ void unreal_engine_py_log_error() {
15471564
}
15481565

15491566
PyErr_Clear();
1550-
}
1567+
}
15511568

15521569
// retrieve a UWorld from a generic UObject (if possible)
15531570
UWorld *ue_get_uworld(ue_PyUObject *py_obj) {

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,17 +786,23 @@ PyObject *py_ue_add_property(ue_PyUObject * self, PyObject * args) {
786786
UProperty *u_property = nullptr;
787787
UClass *u_class = nullptr;
788788
UClass *u_prop_class = nullptr;
789+
UScriptStruct *u_script_struct = nullptr;
789790
bool is_array = false;
790791

791792
if (property_class) {
792793
if (!ue_is_pyuobject(property_class)) {
793794
return PyErr_Format(PyExc_Exception, "property class arg is not a uobject");
794795
}
795796
ue_PyUObject *py_prop_class = (ue_PyUObject *)property_class;
796-
if (!py_prop_class->ue_object->IsA<UClass>()) {
797-
return PyErr_Format(PyExc_Exception, "property class arg is not a UClass");
797+
if (py_prop_class->ue_object->IsA<UClass>()) {
798+
u_prop_class = (UClass *)py_prop_class->ue_object;
799+
}
800+
else if (py_prop_class->ue_object->IsA<UScriptStruct>()) {
801+
u_script_struct = (UScriptStruct *)py_prop_class->ue_object;
802+
}
803+
else {
804+
return PyErr_Format(PyExc_Exception, "property class arg is not a UClass or a UScriptStruct");
798805
}
799-
u_prop_class = (UClass *)py_prop_class->ue_object;
800806
}
801807

802808
EObjectFlags o_flags = RF_Public | RF_MarkAsNative | RF_Transient;
@@ -866,6 +872,12 @@ PyObject *py_ue_add_property(ue_PyUObject * self, PyObject * args) {
866872
obj_prop->SetPropertyClass(u_prop_class);
867873
}
868874
}
875+
if (u_property->GetClass() == UStructProperty::StaticClass()) {
876+
UStructProperty *obj_prop = (UStructProperty *)u_property;
877+
if (u_script_struct) {
878+
obj_prop->Struct = u_script_struct;
879+
}
880+
}
869881
u_property = u_array;
870882
}
871883

@@ -895,6 +907,16 @@ PyObject *py_ue_add_property(ue_PyUObject * self, PyObject * args) {
895907
}
896908
}
897909

910+
else if (u_class == UStructProperty::StaticClass()) {
911+
// ensure it is not an arry as we have already managed it !
912+
if (!is_array) {
913+
UStructProperty *obj_prop = (UStructProperty *)u_property;
914+
if (u_script_struct) {
915+
obj_prop->Struct = u_script_struct;
916+
}
917+
}
918+
}
919+
898920
u_property->SetPropertyFlags(flags);
899921
u_property->ArrayDim = 1;
900922

Source/UnrealEnginePython/Private/Wrappers/UEPyFVector.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ static PyObject *ue_py_fvector_mul(ue_PyFVector *self, PyObject *value) {
206206
if (py_vec) {
207207
vec *= py_vec->vec;
208208
}
209+
else if (ue_PyFRotator *py_rot = py_ue_is_frotator(value)) {
210+
return py_ue_new_fvector(py_rot->rot.RotateVector(vec));
211+
}
212+
else if (ue_PyFQuat *py_quat = py_ue_is_fquat(value)) {
213+
return py_ue_new_fvector(py_quat->quat.RotateVector(vec));
214+
}
209215
else if (PyNumber_Check(value)) {
210216
PyObject *f_value = PyNumber_Float(value);
211217
float f = PyFloat_AsDouble(f_value);
@@ -223,12 +229,6 @@ static PyObject *ue_py_fvector_div(ue_PyFVector *self, PyObject *value) {
223229
return PyErr_Format(PyExc_ZeroDivisionError, "division by zero");
224230
vec /= py_vec->vec;
225231
}
226-
else if (ue_PyFRotator *py_rot = py_ue_is_frotator(value)) {
227-
return py_ue_new_fvector(py_rot->rot.RotateVector(vec));
228-
}
229-
else if (ue_PyFQuat *py_quat = py_ue_is_fquat(value)) {
230-
return py_ue_new_fvector(py_quat->quat.RotateVector(vec));
231-
}
232232
else if (PyNumber_Check(value)) {
233233
PyObject *f_value = PyNumber_Float(value);
234234
float f = PyFloat_AsDouble(f_value);

0 commit comments

Comments
 (0)