Skip to content

Commit 1eed91e

Browse files
author
Roberto De Ioris
committed
owning api
1 parent 766ea83 commit 1eed91e

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,10 @@ static PyMethodDef ue_PyUObject_methods[] = {
656656
{ "auto_root", (PyCFunction)py_ue_auto_root, METH_VARARGS, "" },
657657
{ "remove_from_root", (PyCFunction)py_ue_remove_from_root, METH_VARARGS, "" },
658658

659+
{ "own", (PyCFunction)py_ue_own, METH_VARARGS, "" },
660+
{ "disown", (PyCFunction)py_ue_disown, METH_VARARGS, "" },
661+
{ "is_owned", (PyCFunction)py_ue_is_owned, METH_VARARGS, "" },
662+
659663
{ "find_function", (PyCFunction)py_ue_find_function, METH_VARARGS, "" },
660664

661665
#pragma warning(suppress: 4191)

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,55 @@ PyObject *py_ue_add_to_root(ue_PyUObject *self, PyObject * args)
12441244
Py_RETURN_NONE;
12451245
}
12461246

1247+
PyObject *py_ue_own(ue_PyUObject *self, PyObject * args)
1248+
{
1249+
1250+
ue_py_check(self);
1251+
1252+
if (self->owned)
1253+
{
1254+
return PyErr_Format(PyExc_Exception, "uobject already owned");
1255+
}
1256+
1257+
Py_DECREF(self);
1258+
1259+
self->owned = 1;
1260+
FUnrealEnginePythonHouseKeeper::Get()->TrackUObject(self->ue_object);
1261+
1262+
Py_RETURN_NONE;
1263+
}
1264+
1265+
PyObject *py_ue_disown(ue_PyUObject *self, PyObject * args)
1266+
{
1267+
1268+
ue_py_check(self);
1269+
1270+
if (!self->owned)
1271+
{
1272+
return PyErr_Format(PyExc_Exception, "uobject not owned");
1273+
}
1274+
1275+
Py_INCREF(self);
1276+
1277+
self->owned = 0;
1278+
FUnrealEnginePythonHouseKeeper::Get()->UntrackUObject(self->ue_object);
1279+
1280+
Py_RETURN_NONE;
1281+
}
1282+
1283+
PyObject *py_ue_is_owned(ue_PyUObject *self, PyObject * args)
1284+
{
1285+
1286+
ue_py_check(self);
1287+
1288+
if (!self->owned)
1289+
{
1290+
Py_RETURN_FALSE;
1291+
}
1292+
1293+
Py_RETURN_TRUE;
1294+
}
1295+
12471296
PyObject *py_ue_auto_root(ue_PyUObject *self, PyObject * args)
12481297
{
12491298

Source/UnrealEnginePython/Private/UObject/UEPyObject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ PyObject *py_ue_is_rooted(ue_PyUObject *, PyObject *);
3131
PyObject *py_ue_add_to_root(ue_PyUObject *, PyObject *);
3232
PyObject *py_ue_remove_from_root(ue_PyUObject *, PyObject *);
3333
PyObject *py_ue_auto_root(ue_PyUObject *, PyObject *);
34+
PyObject *py_ue_own(ue_PyUObject *, PyObject *);
35+
PyObject *py_ue_disown(ue_PyUObject *, PyObject *);
36+
PyObject *py_ue_is_owned(ue_PyUObject *, PyObject *);
3437

3538
PyObject *py_ue_save_config(ue_PyUObject *, PyObject *);
3639

0 commit comments

Comments
 (0)