Skip to content

Commit 1c22936

Browse files
author
Roberto De Ioris
committed
added is_valid() method
1 parent ccd04ce commit 1c22936

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
433433
{ "functions", (PyCFunction)py_ue_functions, METH_VARARGS, "" },
434434

435435
{ "is_a", (PyCFunction)py_ue_is_a, METH_VARARGS, "" },
436+
{ "is_valid", (PyCFunction)py_ue_is_valid, METH_VARARGS, "" },
436437
{ "is_child_of", (PyCFunction)py_ue_is_child_of, METH_VARARGS, "" },
437438

438439
{ "call", (PyCFunction)py_ue_call, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ PyObject *py_ue_conditional_begin_destroy(ue_PyUObject *self, PyObject * args)
138138
return Py_None;
139139
}
140140

141+
PyObject *py_ue_is_valid(ue_PyUObject * self, PyObject * args)
142+
{
143+
if (!self->ue_object || !self->ue_object->IsValidLowLevel() || self->ue_object->IsPendingKillOrUnreachable())
144+
{
145+
Py_RETURN_FALSE;
146+
}
147+
148+
Py_RETURN_TRUE;
149+
}
150+
141151
PyObject *py_ue_is_a(ue_PyUObject * self, PyObject * args)
142152
{
143153

@@ -158,13 +168,11 @@ PyObject *py_ue_is_a(ue_PyUObject * self, PyObject * args)
158168

159169
if (self->ue_object->IsA((UClass *)py_obj->ue_object))
160170
{
161-
Py_INCREF(Py_True);
162-
return Py_True;
171+
Py_RETURN_TRUE;
163172
}
164173

165174

166-
Py_INCREF(Py_False);
167-
return Py_False;
175+
Py_RETURN_FALSE;
168176
}
169177

170178
PyObject *py_ue_is_child_of(ue_PyUObject * self, PyObject * args)

Source/UnrealEnginePython/Private/UObject/UEPyObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
PyObject *py_ue_get_class(ue_PyUObject *, PyObject *);
88
PyObject *py_ue_is_a(ue_PyUObject *, PyObject *);
9+
PyObject *py_ue_is_valid(ue_PyUObject *, PyObject *);
910
PyObject *py_ue_is_child_of(ue_PyUObject *, PyObject *);
1011
PyObject *py_ue_call_function(ue_PyUObject *, PyObject *, PyObject *);
1112
PyObject *py_ue_find_function(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)