Skip to content

Commit edabdb5

Browse files
author
Roberto De Ioris
committed
improved ue.new_object()
1 parent 2a01cf7 commit edabdb5

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

Source/UnrealEnginePython/Private/UEPyEngine.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,17 +601,7 @@ PyObject *py_unreal_engine_new_object(PyObject * self, PyObject * args)
601601
if (!new_object)
602602
return PyErr_Format(PyExc_Exception, "unable to create object");
603603

604-
ue_PyUObject *py_uobject = ue_get_python_uobject(new_object);
605-
if (!py_uobject)
606-
{
607-
return PyErr_Format(PyExc_Exception, "unable to create python wrapper for uobject");
608-
}
609-
py_uobject->owned = 1;
610-
611-
// UObject crated explicitely from python, will be managed by python...
612-
FUnrealEnginePythonHouseKeeper::Get()->TrackUObject(new_object);
613-
614-
return (PyObject *)py_uobject;
604+
Py_RETURN_UOBJECT(new_object);
615605
}
616606

617607
PyObject *py_unreal_engine_get_mutable_default(PyObject * self, PyObject * args)

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,19 @@ static PyObject *ue_PyUObject_call(ue_PyUObject *self, PyObject *args, PyObject
13221322
Py_INCREF(py_name);
13231323
PyTuple_SetItem(py_args, 2, py_name);
13241324
}
1325-
PyObject *ret = py_unreal_engine_new_object(nullptr, py_args);
1326-
Py_DECREF(py_args);
1325+
ue_PyUObject *ret = (ue_PyUObject *)py_unreal_engine_new_object(nullptr, py_args);
1326+
if (!ret)
1327+
{
1328+
Py_DECREF(py_args);
1329+
return NULL;
1330+
}
1331+
// when new_object is called the reference counting is 2
1332+
Py_DECREF(ret);
1333+
ret->owned = 1;
1334+
1335+
// UObject crated explicitely from python, will be managed by python...
1336+
FUnrealEnginePythonHouseKeeper::Get()->TrackUObject(ret->ue_object);
1337+
13271338
return (PyObject *)ret;
13281339
}
13291340
// if it is a uscriptstruct, instantiate a new struct

0 commit comments

Comments
 (0)