Skip to content

Commit df6f520

Browse files
author
ikrima
committed
Merge remote-tracking branch 'upstream/master' into bebylon
# Conflicts: # Source/UnrealEnginePython/Private/UEPyModule.cpp # Source/UnrealEnginePython/Private/UEPyUScriptStruct.cpp # Source/UnrealEnginePython/Public/PyUserWidget.h
2 parents e01febc + 912e12e commit df6f520

27 files changed

Lines changed: 985 additions & 81 deletions

‎Source/UnrealEnginePython/Private/PyUserWidget.cpp‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,28 @@ UPyUserWidget::~UPyUserWidget()
371371
// this could trigger the distruction of the python/uobject mapper
372372
Py_XDECREF(py_uobject);
373373
}
374+
375+
void UPyUserWidget::CallPythonUserWidgetMethod(FString method_name, FString args)
376+
{
377+
if (!py_user_widget_instance)
378+
return;
379+
380+
FScopePythonGIL gil;
381+
382+
PyObject *ret = nullptr;
383+
if (args.IsEmpty())
384+
{
385+
ret = PyObject_CallMethod(py_user_widget_instance, TCHAR_TO_UTF8(*method_name), NULL);
386+
}
387+
else
388+
{
389+
ret = PyObject_CallMethod(py_user_widget_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
390+
}
391+
392+
if (!ret)
393+
{
394+
unreal_engine_py_log_error();
395+
return;
396+
}
397+
Py_DECREF(ret);
398+
}

‎Source/UnrealEnginePython/Private/UEPyEngine.cpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ PyObject *py_unreal_engine_string_to_guid(PyObject * self, PyObject * args)
462462
char *str;
463463
if (!PyArg_ParseTuple(args, "s:string_to_guid", &str))
464464
{
465-
return NULL;
465+
return nullptr;
466466
}
467467

468468
FGuid guid;
@@ -481,7 +481,21 @@ PyObject *py_unreal_engine_new_guid(PyObject * self, PyObject * args)
481481
FGuid guid = FGuid::NewGuid();
482482

483483
return py_ue_new_uscriptstruct(FindObject<UScriptStruct>(ANY_PACKAGE, UTF8_TO_TCHAR((char *)"Guid")), (uint8 *)&guid);
484+
}
485+
486+
PyObject *py_unreal_engine_guid_to_string(PyObject * self, PyObject * args)
487+
{
488+
PyObject *py_guid;
489+
if (!PyArg_ParseTuple(args, "O:guid_to_string", &py_guid))
490+
{
491+
return nullptr;
492+
}
493+
494+
FGuid *guid = ue_py_check_fguid(py_guid);
495+
if (!guid)
496+
return PyErr_Format(PyExc_Exception, "object is not a FGuid");
484497

498+
return PyUnicode_FromString(TCHAR_TO_UTF8(*guid->ToString()));
485499
}
486500

487501
PyObject *py_unreal_engine_slate_tick(PyObject * self, PyObject * args)

‎Source/UnrealEnginePython/Private/UEPyEngine.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ PyObject *py_unreal_engine_unload_package(PyObject *, PyObject *);
3838

3939
PyObject *py_unreal_engine_string_to_guid(PyObject *, PyObject *);
4040
PyObject *py_unreal_engine_new_guid(PyObject *, PyObject *);
41+
PyObject *py_unreal_engine_guid_to_string(PyObject *, PyObject *);
4142

4243
PyObject *py_unreal_engine_engine_tick(PyObject *, PyObject *);
4344
PyObject *py_unreal_engine_slate_tick(PyObject *, PyObject *);

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 86 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "UObject/UEPyAnimSequence.h"
3636
#include "UObject/UEPyCapture.h"
3737
#include "UObject/UEPyLandscape.h"
38+
#include "UObject/UEPyUserDefinedStruct.h"
39+
#include "UObject/UEPyDataTable.h"
3840

3941

4042
#include "UEPyAssetUserData.h"
@@ -53,6 +55,12 @@
5355

5456
#include "Slate/UEPySlate.h"
5557

58+
#if ENGINE_MINOR_VERSION < 18
59+
#define USoftObjectProperty UAssetObjectProperty
60+
#define USoftClassProperty UAssetClassProperty
61+
typedef FAssetPtr FSoftObjectPtr;
62+
#endif
63+
5664
DEFINE_LOG_CATEGORY(LogPython);
5765

5866

@@ -267,6 +275,7 @@ static PyMethodDef unreal_engine_methods[] = {
267275

268276
{ "string_to_guid", py_unreal_engine_string_to_guid, METH_VARARGS, "" },
269277
{ "new_guid", py_unreal_engine_new_guid, METH_VARARGS, "" },
278+
{ "guid_to_string", py_unreal_engine_guid_to_string, METH_VARARGS, "" },
270279

271280
{ "heightmap_expand", py_unreal_engine_heightmap_expand, METH_VARARGS, "" },
272281
{ "heightmap_import", py_unreal_engine_heightmap_import, METH_VARARGS, "" },
@@ -279,7 +288,7 @@ static PyMethodDef unreal_engine_methods[] = {
279288
{ "create_blueprint_from_actor", py_unreal_engine_create_blueprint_from_actor, METH_VARARGS, "" },
280289
{ "replace_blueprint", py_unreal_engine_replace_blueprint, METH_VARARGS, "" },
281290
{ "get_blueprint_hierarchy_from_class", py_unreal_engine_get_blueprint_hierarchy_from_class, METH_VARARGS, "" },
282-
{ "reload_blueprint", py_unreal_engine_reload_blueprint, METH_VARARGS, "" },
291+
{ "reload_blueprint", py_unreal_engine_reload_blueprint, METH_VARARGS, "" },
283292
{ "compile_blueprint", py_unreal_engine_compile_blueprint, METH_VARARGS, "" },
284293
{ "blueprint_add_member_variable", py_unreal_engine_blueprint_add_member_variable, METH_VARARGS, "" },
285294
{ "blueprint_add_event_dispatcher", py_unreal_engine_blueprint_add_event_dispatcher, METH_VARARGS, "" },
@@ -489,6 +498,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
489498
{ "get_py_proxy", (PyCFunction)py_ue_get_py_proxy, METH_VARARGS, "" },
490499

491500
{ "post_edit_change", (PyCFunction)py_ue_post_edit_change, METH_VARARGS, "" },
501+
{ "post_edit_change_property", (PyCFunction)py_ue_post_edit_change_property, METH_VARARGS, "" },
492502
{ "pre_edit_change", (PyCFunction)py_ue_pre_edit_change, METH_VARARGS, "" },
493503
{ "modify", (PyCFunction)py_ue_modify, METH_VARARGS, "" },
494504

@@ -531,6 +541,20 @@ static PyMethodDef ue_PyUObject_methods[] = {
531541
{ "node_reconstruct", (PyCFunction)py_ue_node_reconstruct, METH_VARARGS, "" },
532542

533543
{ "get_material_graph", (PyCFunction)py_ue_get_material_graph, METH_VARARGS, "" },
544+
545+
{ "struct_add_variable", (PyCFunction)py_ue_struct_add_variable, METH_VARARGS, "" },
546+
{ "struct_get_variables", (PyCFunction)py_ue_struct_get_variables, METH_VARARGS, "" },
547+
{ "struct_remove_variable", (PyCFunction)py_ue_struct_remove_variable, METH_VARARGS, "" },
548+
{ "struct_move_variable_up", (PyCFunction)py_ue_struct_move_variable_up, METH_VARARGS, "" },
549+
{ "struct_move_variable_down", (PyCFunction)py_ue_struct_move_variable_down, METH_VARARGS, "" },
550+
551+
{ "data_table_add_row", (PyCFunction)py_ue_data_table_add_row, METH_VARARGS, "" },
552+
{ "data_table_remove_row", (PyCFunction)py_ue_data_table_remove_row, METH_VARARGS, "" },
553+
{ "data_table_rename_row", (PyCFunction)py_ue_data_table_rename_row, METH_VARARGS, "" },
554+
{ "data_table_as_dict", (PyCFunction)py_ue_data_table_as_dict, METH_VARARGS, "" },
555+
{ "data_table_as_json", (PyCFunction)py_ue_data_table_as_json, METH_VARARGS, "" },
556+
{ "data_table_find_row", (PyCFunction)py_ue_data_table_find_row, METH_VARARGS, "" },
557+
{ "data_table_get_all_rows", (PyCFunction)py_ue_data_table_get_all_rows, METH_VARARGS, "" },
534558
#endif
535559

536560
{ "is_rooted", (PyCFunction)py_ue_is_rooted, METH_VARARGS, "" },
@@ -700,7 +724,14 @@ static PyMethodDef ue_PyUObject_methods[] = {
700724
{ "get_current_level", (PyCFunction)py_ue_get_current_level, METH_VARARGS, "" },
701725
{ "set_current_level", (PyCFunction)py_ue_set_current_level, METH_VARARGS, "" },
702726

727+
#if WITH_EDITOR
728+
{ "add_foliage_asset", (PyCFunction)py_ue_add_foliage_asset, METH_VARARGS, "" },
729+
#endif
730+
{ "get_instanced_foliage_actor_for_current_level", (PyCFunction)py_ue_get_instanced_foliage_actor_for_current_level, METH_VARARGS, "" },
731+
732+
703733
{ "add_actor_component", (PyCFunction)py_ue_add_actor_component, METH_VARARGS, "" },
734+
{ "add_instance_component", (PyCFunction)py_ue_add_instance_component, METH_VARARGS, "" },
704735
{ "add_actor_root_component", (PyCFunction)py_ue_add_actor_root_component, METH_VARARGS, "" },
705736
{ "get_actor_component_by_type", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },
706737
{ "get_component_by_type", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },
@@ -947,7 +978,7 @@ void ue_pydelegates_cleanup(ue_PyUObject *self)
947978
#endif
948979
py_delegate->RemoveFromRoot();
949980
}
950-
}
981+
}
951982
self->python_delegates_gc->clear();
952983
delete self->python_delegates_gc;
953984
self->python_delegates_gc = nullptr;
@@ -1043,9 +1074,9 @@ static PyObject *ue_PyUObject_getattro(ue_PyUObject *self, PyObject *attr_name)
10431074
#else
10441075
return PyLong_FromLong(u_enum->FindEnumIndex(item.Key));
10451076
#endif
1046-
}
10471077
}
10481078
}
1079+
}
10491080
#endif
10501081
if (self->ue_object->IsA<UEnum>())
10511082
{
@@ -1057,16 +1088,16 @@ static PyObject *ue_PyUObject_getattro(ue_PyUObject *self, PyObject *attr_name)
10571088
return PyLong_FromLong(u_enum->FindEnumIndex(FName(UTF8_TO_TCHAR(attr))));
10581089
#endif
10591090
}
1060-
}
1091+
}
10611092

10621093
if (function)
10631094
{
10641095
// swallow previous exception
10651096
PyErr_Clear();
10661097
return py_ue_new_callable(function, self->ue_object);
10671098
}
1068-
}
10691099
}
1100+
}
10701101
return ret;
10711102
}
10721103

@@ -2059,7 +2090,7 @@ void unreal_engine_py_log_error()
20592090
if (zero)
20602091
{
20612092
msg = PyBytes_AsString(zero);
2062-
}
2093+
}
20632094
#else
20642095
msg = PyString_AsString(PyObject_Str(value));
20652096
#endif
@@ -2114,7 +2145,7 @@ void unreal_engine_py_log_error()
21142145
}
21152146

21162147
PyErr_Clear();
2117-
}
2148+
}
21182149

21192150
// retrieve a UWorld from a generic UObject (if possible)
21202151
UWorld *ue_get_uworld(ue_PyUObject *py_obj)
@@ -2245,8 +2276,7 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer)
22452276
Py_INCREF(ret);
22462277
return (PyObject *)ret;
22472278
}
2248-
Py_INCREF(Py_None);
2249-
return Py_None;
2279+
Py_RETURN_NONE;
22502280
}
22512281

22522282
if (auto casted_prop = Cast<UClassProperty>(prop))
@@ -2764,24 +2794,47 @@ bool ue_py_convert_pyobject(PyObject *py_obj, UProperty *prop, uint8 *buffer)
27642794
ue_PyUObject *ue_obj = (ue_PyUObject *)py_obj;
27652795
if (ue_obj->ue_object->IsA<UClass>())
27662796
{
2767-
auto casted_prop = Cast<UClassProperty>(prop);
2768-
if (!casted_prop)
2797+
if (auto casted_prop = Cast<UClassProperty>(prop))
2798+
{
2799+
casted_prop->SetPropertyValue_InContainer(buffer, ue_obj->ue_object);
2800+
return true;
2801+
}
2802+
else if (auto casted_prop_soft_class = Cast<USoftClassProperty>(prop))
2803+
{
2804+
casted_prop_soft_class->SetPropertyValue_InContainer(buffer, FSoftObjectPtr(ue_obj->ue_object));
2805+
return true;
2806+
}
2807+
else if (auto casted_prop_soft_object = Cast<USoftObjectProperty>(prop))
2808+
{
2809+
casted_prop_soft_object->SetPropertyValue_InContainer(buffer, FSoftObjectPtr(ue_obj->ue_object));
2810+
return true;
2811+
}
2812+
27692813
return false;
2770-
casted_prop->SetPropertyValue_InContainer(buffer, (UClass *)ue_obj->ue_object);
2771-
return true;
27722814
}
27732815

2816+
27742817
if (ue_obj->ue_object->IsA<UObject>())
27752818
{
2776-
auto casted_prop = Cast<UObjectPropertyBase>(prop);
2777-
if (!casted_prop)
2778-
return false;
2819+
if (auto casted_prop = Cast<UObjectPropertyBase>(prop))
2820+
{
27792821
// ensure the object type is correct, otherwise crash could happen (soon or later)
27802822
if (!ue_obj->ue_object->IsA(casted_prop->PropertyClass))
27812823
return false;
27822824
casted_prop->SetObjectPropertyValue_InContainer(buffer, ue_obj->ue_object);
27832825
return true;
27842826
}
2827+
else if (auto casted_prop_soft_object = Cast<USoftObjectProperty>(prop))
2828+
2829+
{
2830+
if (!ue_obj->ue_object->IsA(casted_prop_soft_object->PropertyClass))
2831+
return false;
2832+
casted_prop_soft_object->SetPropertyValue_InContainer(buffer, FSoftObjectPtr(ue_obj->ue_object));
2833+
return true;
2834+
}
2835+
2836+
}
2837+
return false;
27852838
}
27862839

27872840
if (py_obj == Py_None)
@@ -2994,10 +3047,10 @@ PyObject *py_ue_ufunction_call(UFunction *u_function, UObject *u_obj, PyObject *
29943047
#else
29953048
prop->ImportText(*default_key_value, prop->ContainerPtrToValuePtr<uint8>(buffer), PPF_Localized, NULL);
29963049
#endif
2997-
}
3050+
}
29983051
#endif
29993052

3000-
}
3053+
}
30013054

30023055
Py_ssize_t tuple_len = PyTuple_Size(args);
30033056

@@ -3481,6 +3534,21 @@ UFunction *unreal_engine_add_function(UClass *u_class, char *name, PyObject *py_
34813534
return function;
34823535
}
34833536

3537+
FGuid *ue_py_check_fguid(PyObject *py_obj)
3538+
{
3539+
ue_PyUScriptStruct *ue_py_struct = py_ue_is_uscriptstruct(py_obj);
3540+
if (!ue_py_struct)
3541+
{
3542+
return nullptr;
3543+
}
3544+
3545+
if (ue_py_struct->u_struct == FindObject<UScriptStruct>(ANY_PACKAGE, UTF8_TO_TCHAR((char *)"Guid")))
3546+
{
3547+
return (FGuid*)ue_py_struct->data;
3548+
}
3549+
3550+
return nullptr;
3551+
}
34843552
uint8 * do_ue_py_check_struct(PyObject *py_obj, UScriptStruct* chk_u_struct)
34853553
{
34863554
ue_PyUScriptStruct *ue_py_struct = py_ue_is_uscriptstruct(py_obj);

‎Source/UnrealEnginePython/Private/UEPyModule.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ bool do_ue_py_check_childstruct(PyObject *py_obj, UScriptStruct* parent_u_struct
6868
template <typename T> bool ue_py_check_childstruct(PyObject *py_obj) {
6969
return do_ue_py_check_childstruct(py_obj, T::StaticStruct());
7070
}
71+
72+
FGuid *ue_py_check_fguid(PyObject *);

0 commit comments

Comments
 (0)