Skip to content

Commit 68fd1ac

Browse files
author
Roberto De Ioris
committed
improved flags management
1 parent 09ca1d5 commit 68fd1ac

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ static PyMethodDef ue_PyUObject_methods[] = {
721721
{ "class_set_flags", (PyCFunction)py_ue_class_set_flags, METH_VARARGS, "" },
722722
{ "get_obj_flags", (PyCFunction)py_ue_get_obj_flags, METH_VARARGS, "" },
723723
{ "set_obj_flags", (PyCFunction)py_ue_set_obj_flags, METH_VARARGS, "" },
724+
{ "clear_obj_flags", (PyCFunction)py_ue_clear_obj_flags, METH_VARARGS, "" },
725+
{ "reset_obj_flags", (PyCFunction)py_ue_reset_obj_flags, METH_VARARGS, "" },
724726

725727
#if WITH_EDITOR
726728
{ "class_get_config_name", (PyCFunction)py_ue_class_get_config_name, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,47 @@ PyObject *py_ue_set_obj_flags(ue_PyUObject * self, PyObject * args)
8383
ue_py_check(self);
8484

8585
uint64 flags;
86-
if (!PyArg_ParseTuple(args, "K:set_obj_flags", &flags))
86+
PyObject *py_reset = nullptr;
87+
if (!PyArg_ParseTuple(args, "K|O:set_obj_flags", &flags, &py_reset))
8788
{
8889
return nullptr;
8990
}
9091

92+
if (py_reset && PyObject_IsTrue(py_reset))
93+
{
94+
self->ue_object->ClearFlags(self->ue_object->GetFlags());
95+
}
96+
9197
self->ue_object->SetFlags((EObjectFlags)flags);
9298

9399
Py_RETURN_NONE;
94100
}
95101

102+
PyObject *py_ue_clear_obj_flags(ue_PyUObject * self, PyObject * args)
103+
{
104+
105+
ue_py_check(self);
106+
107+
uint64 flags;
108+
if (!PyArg_ParseTuple(args, "K:clear_obj_flags", &flags))
109+
{
110+
return nullptr;
111+
}
112+
113+
self->ue_object->ClearFlags((EObjectFlags)flags);
114+
115+
Py_RETURN_NONE;
116+
}
117+
118+
PyObject *py_ue_reset_obj_flags(ue_PyUObject * self, PyObject * args)
119+
{
120+
121+
ue_py_check(self);
122+
123+
self->ue_object->ClearFlags(self->ue_object->GetFlags());
124+
125+
Py_RETURN_NONE;
126+
}
96127

97128
#if WITH_EDITOR
98129
PyObject *py_ue_class_set_config_name(ue_PyUObject * self, PyObject * args)
@@ -723,7 +754,7 @@ PyObject *py_ue_set_property_flags(ue_PyUObject *self, PyObject * args)
723754
else
724755
{
725756
u_struct = (UStruct *)self->ue_object->GetClass();
726-
}
757+
}
727758

728759
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
729760
if (!u_property)
@@ -771,7 +802,7 @@ PyObject *py_ue_add_property_flags(ue_PyUObject *self, PyObject * args)
771802
u_property->SetPropertyFlags(u_property->GetPropertyFlags() | (EPropertyFlags)flags);
772803
#endif
773804
Py_RETURN_NONE;
774-
}
805+
}
775806

776807
PyObject *py_ue_get_property_flags(ue_PyUObject *self, PyObject * args)
777808
{
@@ -1543,7 +1574,7 @@ PyObject *py_ue_add_property(ue_PyUObject * self, PyObject * args)
15431574
if (is_array || is_map)
15441575
scope->MarkPendingKill();
15451576
return PyErr_Format(PyExc_Exception, "unable to allocate new UProperty");
1546-
}
1577+
}
15471578
UMapProperty *u_map = (UMapProperty *)scope;
15481579

15491580
#if ENGINE_MINOR_VERSION < 20
@@ -1592,7 +1623,7 @@ PyObject *py_ue_add_property(ue_PyUObject * self, PyObject * args)
15921623
u_map->ValueProp = u_property2;
15931624

15941625
u_property = u_map;
1595-
}
1626+
}
15961627
#endif
15971628

15981629
if (u_class == UMulticastDelegateProperty::StaticClass())

Source/UnrealEnginePython/Private/UObject/UEPyObject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ PyObject *py_ue_class_get_flags(ue_PyUObject *, PyObject *);
7272
PyObject *py_ue_class_set_flags(ue_PyUObject *, PyObject *);
7373
PyObject *py_ue_get_obj_flags(ue_PyUObject *, PyObject *);
7474
PyObject *py_ue_set_obj_flags(ue_PyUObject *, PyObject *);
75+
PyObject *py_ue_clear_obj_flags(ue_PyUObject *, PyObject *);
76+
PyObject *py_ue_reset_obj_flags(ue_PyUObject *, PyObject *);
7577
PyObject *py_ue_delegate_bind_ufunction(ue_PyUObject *, PyObject *);
7678

7779

0 commit comments

Comments
 (0)