@@ -334,6 +334,53 @@ PyObject *py_ue_add_function(ue_PyUObject * self, PyObject * args) {
334334 return Py_None;
335335}
336336
337+ PyObject *py_ue_add_property (ue_PyUObject * self, PyObject * args) {
338+
339+ ue_py_check (self);
340+
341+ PyObject *obj;
342+ char *name;
343+ PyObject *replicate = nullptr ;
344+ if (!PyArg_ParseTuple (args, " Os|O:add_property" , &obj, &name, &replicate)) {
345+ return NULL ;
346+ }
347+
348+ if (!self->ue_object ->IsA <UStruct>())
349+ return PyErr_Format (PyExc_Exception, " uobject is not a UStruct" );
350+
351+ if (!ue_is_pyuobject (obj)) {
352+ return PyErr_Format (PyExc_Exception, " argument is not a UObject" );
353+ }
354+
355+ ue_PyUObject *py_obj = (ue_PyUObject *)obj;
356+
357+ if (!py_obj->ue_object ->IsA <UClass>()) {
358+ return PyErr_Format (PyExc_Exception, " uobject is not a UClass" );
359+ }
360+
361+ UProperty *u_property = NewObject<UProperty>(self->ue_object , (UClass *)py_obj->ue_object , UTF8_TO_TCHAR (name));
362+ if (!u_property)
363+ return PyErr_Format (PyExc_Exception, " unable to allocate new UProperty" );
364+
365+ uint64 flags = CPF_Edit;
366+ if (replicate && PyObject_IsTrue (replicate)) {
367+ flags |= CPF_Net;
368+ }
369+
370+ u_property->SetPropertyFlags (flags);
371+
372+ UStruct *u_struct = (UStruct *)self->ue_object ;
373+
374+ u_struct->AddCppProperty (u_property);
375+
376+ ue_PyUObject *ret = ue_get_python_wrapper (u_property);
377+ if (!ret)
378+ return PyErr_Format (PyExc_Exception, " PyUObject is in invalid state" );
379+ Py_INCREF (ret);
380+ return (PyObject *)ret;
381+
382+ }
383+
337384PyObject *py_ue_as_dict (ue_PyUObject * self, PyObject * args) {
338385
339386 ue_py_check (self);
@@ -370,6 +417,8 @@ PyObject *py_ue_save_package(ue_PyUObject * self, PyObject * args) {
370417 return NULL ;
371418 }
372419
420+ // NOTE maybe we should check for transient object, to avoid crashes
421+
373422 if (UPackage::SavePackage (GetTransientPackage (), self->ue_object , EObjectFlags::RF_NoFlags, UTF8_TO_TCHAR (filename))) {
374423 Py_INCREF (Py_True);
375424 return Py_True;
0 commit comments