Skip to content

Commit 80a8e1a

Browse files
author
Roberto De Ioris
committed
added copy_properties_for_unrelated_objects
1 parent 4be2732 commit 80a8e1a

File tree

4 files changed

+80
-8
lines changed

4 files changed

+80
-8
lines changed

Source/UnrealEnginePython/Private/UEPyEngine.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,4 +1159,71 @@ PyObject *py_unreal_engine_save_file_dialog(PyObject *self, PyObject * args)
11591159
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*file)));
11601160
}
11611161
return py_list;
1162+
}
1163+
1164+
1165+
PyObject *py_unreal_engine_copy_properties_for_unrelated_objects(PyObject * self, PyObject * args, PyObject *kwargs)
1166+
{
1167+
1168+
PyObject *old_py_object;
1169+
PyObject *new_py_object;
1170+
1171+
PyObject *py_aggressive_default_subobject_replacement = nullptr;
1172+
PyObject *py_copy_deprecated_properties = nullptr;
1173+
PyObject *py_do_delta = nullptr;
1174+
PyObject *py_notify_object_replacement = nullptr;
1175+
PyObject *py_preserve_root_component = nullptr;
1176+
PyObject *py_replace_object_class_references = nullptr;
1177+
PyObject *py_skip_compiler_generated_defaults = nullptr;
1178+
1179+
static char *kw_names[] = {
1180+
(char *)"old_object",
1181+
(char *)"new_object",
1182+
(char *)"aggressive_default_subobject_replacement",
1183+
(char *)"copy_deprecated_properties",
1184+
(char *)"do_delta",
1185+
(char *)"notify_object_replacement",
1186+
(char *)"preserve_root_component",
1187+
(char *)"replace_object_class_references",
1188+
(char *)"skip_compiler_generated_defaults",
1189+
nullptr
1190+
};
1191+
1192+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|OOOOOOO:copy_properties_for_unrelated_objects", kw_names,
1193+
&old_py_object,
1194+
&new_py_object,
1195+
&py_aggressive_default_subobject_replacement,
1196+
&py_copy_deprecated_properties,
1197+
&py_do_delta,
1198+
&py_notify_object_replacement,
1199+
&py_preserve_root_component,
1200+
&py_replace_object_class_references,
1201+
&py_skip_compiler_generated_defaults))
1202+
{
1203+
return nullptr;
1204+
}
1205+
1206+
UObject *old_object = ue_py_check_type<UObject>(old_py_object);
1207+
if (!old_object)
1208+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
1209+
1210+
UObject *new_object = ue_py_check_type<UObject>(new_py_object);
1211+
if (!new_object)
1212+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
1213+
1214+
UEngine::FCopyPropertiesForUnrelatedObjectsParams params;
1215+
params.bAggressiveDefaultSubobjectReplacement = (py_aggressive_default_subobject_replacement && PyObject_IsTrue(py_aggressive_default_subobject_replacement));
1216+
params.bCopyDeprecatedProperties = (py_copy_deprecated_properties && PyObject_IsTrue(py_copy_deprecated_properties));
1217+
params.bDoDelta = (py_do_delta && PyObject_IsTrue(py_do_delta));
1218+
params.bNotifyObjectReplacement = (py_notify_object_replacement && PyObject_IsTrue(py_notify_object_replacement));
1219+
params.bPreserveRootComponent = (py_preserve_root_component && PyObject_IsTrue(py_preserve_root_component));
1220+
params.bReplaceObjectClassReferences = (py_replace_object_class_references && PyObject_IsTrue(py_replace_object_class_references));
1221+
params.bSkipCompilerGeneratedDefaults = (py_skip_compiler_generated_defaults && PyObject_IsTrue(py_skip_compiler_generated_defaults));
1222+
1223+
GEngine->CopyPropertiesForUnrelatedObjects(
1224+
old_object,
1225+
new_object,
1226+
params);
1227+
1228+
Py_RETURN_NONE;
11621229
}

Source/UnrealEnginePython/Private/UEPyEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ PyObject *py_unreal_engine_open_font_dialog(PyObject *, PyObject *);
6969
PyObject *py_unreal_engine_open_directory_dialog(PyObject *, PyObject *);
7070
PyObject *py_unreal_engine_save_file_dialog(PyObject *, PyObject *);
7171

72+
PyObject *py_unreal_engine_copy_properties_for_unrelated_objects(PyObject *, PyObject *, PyObject *);
73+
7274
#if WITH_EDITOR
7375
PyObject *py_unreal_engine_editor_get_active_viewport_screenshot(PyObject *, PyObject *);
7476
PyObject *py_unreal_engine_editor_get_pie_viewport_screenshot(PyObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ static PyMethodDef unreal_engine_methods[] = {
374374
{ "unregister_settings", py_unreal_engine_unregister_settings, METH_VARARGS, "" },
375375
#endif
376376

377+
#pragma warning(suppress: 4191)
378+
{ "copy_properties_for_unrelated_objects", (PyCFunction)py_unreal_engine_copy_properties_for_unrelated_objects, METH_VARARGS | METH_KEYWORDS, "" },
379+
377380

378381
{ NULL, NULL },
379382
};
@@ -926,7 +929,7 @@ void ue_pydelegates_cleanup(ue_PyUObject *self)
926929
#endif
927930
py_delegate->RemoveFromRoot();
928931
}
929-
}
932+
}
930933
self->python_delegates_gc->clear();
931934
delete self->python_delegates_gc;
932935
self->python_delegates_gc = nullptr;
@@ -1022,9 +1025,9 @@ static PyObject *ue_PyUObject_getattro(ue_PyUObject *self, PyObject *attr_name)
10221025
#else
10231026
return PyLong_FromLong(u_enum->FindEnumIndex(item.Key));
10241027
#endif
1025-
}
10261028
}
10271029
}
1030+
}
10281031
#endif
10291032
if (self->ue_object->IsA<UEnum>())
10301033
{
@@ -1036,16 +1039,16 @@ static PyObject *ue_PyUObject_getattro(ue_PyUObject *self, PyObject *attr_name)
10361039
return PyLong_FromLong(u_enum->FindEnumIndex(FName(UTF8_TO_TCHAR(attr))));
10371040
#endif
10381041
}
1039-
}
1042+
}
10401043

10411044
if (function)
10421045
{
10431046
// swallow previous exception
10441047
PyErr_Clear();
10451048
return py_ue_new_callable(function, self->ue_object);
10461049
}
1047-
}
10481050
}
1051+
}
10491052
return ret;
10501053
}
10511054

@@ -2034,7 +2037,7 @@ void unreal_engine_py_log_error()
20342037
if (zero)
20352038
{
20362039
msg = PyBytes_AsString(zero);
2037-
}
2040+
}
20382041
#else
20392042
msg = PyString_AsString(PyObject_Str(value));
20402043
#endif
@@ -2963,10 +2966,10 @@ PyObject *py_ue_ufunction_call(UFunction *u_function, UObject *u_obj, PyObject *
29632966
prop->ImportText(*default_key_value, prop->ContainerPtrToValuePtr<uint8>(buffer), PPF_None, NULL);
29642967
#else
29652968
prop->ImportText(*default_key_value, prop->ContainerPtrToValuePtr<uint8>(buffer), PPF_Localized, NULL);
2966-
#endif
2967-
}
29682969
#endif
29692970
}
2971+
#endif
2972+
}
29702973

29712974
Py_ssize_t tuple_len = PyTuple_Size(args);
29722975

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ PyObject *py_ue_class_get_config_name(ue_PyUObject * self, PyObject * args)
9999

100100
ue_py_check(self);
101101

102-
102+
103103
UClass *u_class = ue_py_check_type<UClass>(self);
104104
if (!u_class)
105105
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");

0 commit comments

Comments
 (0)