Skip to content

Commit 5f36fd6

Browse files
author
ikrima
committed
Merge commit 'cb19b3859f52330ccae02cc04990ec14d686d19d' into bebylon
2 parents f05b979 + cb19b38 commit 5f36fd6

3 files changed

Lines changed: 69 additions & 24 deletions

File tree

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,46 +1531,58 @@ PyObject *py_unreal_engine_blueprint_add_member_variable(PyObject * self, PyObje
15311531

15321532
PyObject *py_blueprint;
15331533
char *name;
1534-
char *in_type;
1534+
PyObject *py_type;
15351535
PyObject *py_is_array = nullptr;
1536-
if (!PyArg_ParseTuple(args, "Oss|O:blueprint_add_member_variable", &py_blueprint, &name, &in_type, &py_is_array))
1536+
char *default_value = nullptr;
1537+
if (!PyArg_ParseTuple(args, "OsO|Os:blueprint_add_member_variable", &py_blueprint, &name, &py_type, &py_is_array, &default_value))
15371538
{
1538-
return NULL;
1539+
return nullptr;
15391540
}
15401541

1541-
if (!ue_is_pyuobject(py_blueprint))
1542-
{
1543-
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
1544-
}
1542+
UBlueprint *bp = ue_py_check_type<UBlueprint>(py_blueprint);
1543+
if (!bp)
1544+
return PyErr_Format(PyExc_Exception, "uobject is not a Blueprint");
15451545

1546-
ue_PyUObject *py_obj = (ue_PyUObject *)py_blueprint;
1547-
if (!py_obj->ue_object->IsA<UBlueprint>())
1548-
return PyErr_Format(PyExc_Exception, "uobject is not a UBlueprint");
1549-
UBlueprint *bp = (UBlueprint *)py_obj->ue_object;
1546+
FEdGraphPinType pin;
15501547

1551-
bool is_array = false;
1552-
if (py_is_array && PyObject_IsTrue(py_is_array))
1553-
is_array = true;
1548+
if (PyUnicode_Check(py_type))
1549+
{
1550+
char *in_type = PyUnicode_AsUTF8(py_type);
1551+
1552+
bool is_array = false;
1553+
if (py_is_array && PyObject_IsTrue(py_is_array))
1554+
is_array = true;
15541555
#if ENGINE_MINOR_VERSION > 14
1555-
FEdGraphPinType pin;
1556-
pin.PinCategory = UTF8_TO_TCHAR(in_type);
1556+
pin.PinCategory = UTF8_TO_TCHAR(in_type);
15571557
#if ENGINE_MINOR_VERSION >= 17
1558-
pin.ContainerType = is_array ? EPinContainerType::Array : EPinContainerType::None;
1558+
pin.ContainerType = is_array ? EPinContainerType::Array : EPinContainerType::None;
15591559
#else
1560-
pin.bIsArray = is_array;
1560+
pin.bIsArray = is_array;
15611561
#endif
15621562
#else
1563-
FEdGraphPinType pin(UTF8_TO_TCHAR(in_type), FString(""), nullptr, is_array, false);
1563+
FEdGraphPinType pin2(UTF8_TO_TCHAR(in_type), FString(""), nullptr, is_array, false);
1564+
pin = pin2;
15641565
#endif
1566+
}
1567+
else
1568+
{
1569+
FEdGraphPinType *pinptr = ue_py_check_struct<FEdGraphPinType>(py_type);
1570+
if (!pinptr)
1571+
return PyErr_Format(PyExc_Exception, "argument is not a EdGraphPinType");
1572+
pin = *pinptr;
1573+
}
1574+
1575+
FString DefaultValue = FString("");
15651576

1566-
if (FBlueprintEditorUtils::AddMemberVariable(bp, UTF8_TO_TCHAR(name), pin))
1577+
if (default_value)
1578+
DefaultValue = FString(default_value);
1579+
1580+
if (FBlueprintEditorUtils::AddMemberVariable(bp, UTF8_TO_TCHAR(name), pin, DefaultValue))
15671581
{
1568-
Py_INCREF(Py_True);
1569-
return Py_True;
1582+
Py_RETURN_TRUE;
15701583
}
15711584

1572-
Py_INCREF(Py_False);
1573-
return Py_False;
1585+
Py_RETURN_FALSE;
15741586
}
15751587

15761588
PyObject *py_unreal_engine_blueprint_set_variable_visibility(PyObject * self, PyObject * args)

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,11 @@ bool ue_py_convert_pyobject(PyObject *py_obj, UProperty *prop, uint8 *buffer, in
25202520
casted_prop_soft_object->SetPropertyValue_InContainer(buffer, FSoftObjectPtr(ue_obj->ue_object), index);
25212521
return true;
25222522
}
2523+
else if (auto casted_prop_weak_object = Cast<UWeakObjectProperty>(prop))
2524+
{
2525+
casted_prop_weak_object->SetPropertyValue_InContainer(buffer, FWeakObjectPtr(ue_obj->ue_object), index);
2526+
return true;
2527+
}
25232528

25242529
return false;
25252530
}

examples/blueprint_variables.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import unreal_engine as ue
2+
3+
from unreal_engine.classes import Material, BlueprintFactory, Blueprint, Actor, Texture2D, SkeletalMesh
4+
from unreal_engine.structs import EdGraphPinType, Vector, Rotator, EdGraphTerminalType
5+
from unreal_engine.enums import EPinContainerType
6+
7+
import time
8+
9+
bp = ue.create_blueprint(Actor, '/Game/FooActor' + str(int(time.time())))
10+
11+
pin = EdGraphPinType(PinCategory='object', PinSubCategoryObject=Material)
12+
ue.blueprint_add_member_variable(bp, 'TestMat', pin, None, '/Engine/MapTemplates/Materials/BasicAsset03.BasicAsset03')
13+
14+
pin = EdGraphPinType(PinCategory='class', PinSubCategoryObject=Texture2D)
15+
ue.blueprint_add_member_variable(bp, 'TestTextureClass', pin)
16+
17+
pin = EdGraphPinType(PinCategory='struct',PinSubCategoryObject=Vector)
18+
ue.blueprint_add_member_variable(bp, 'TestVector', pin, None, '17,22,30')
19+
20+
pin = EdGraphPinType(PinCategory='struct',PinSubCategoryObject=Rotator,ContainerType=EPinContainerType.Array)
21+
ue.blueprint_add_member_variable(bp, 'TestRotator', pin, None, '((Pitch=0.000000,Yaw=3.000000,Roll=0.000000),(Pitch=1.000000,Yaw=0.000000,Roll=0.000000))')
22+
23+
pin = EdGraphPinType(PinCategory='string',ContainerType=EPinContainerType.Map,PinValueType=EdGraphTerminalType(TerminalCategory='object',TerminalSubCategoryObject=SkeletalMesh))
24+
ue.blueprint_add_member_variable(bp, 'TestMap', pin, None, '(("firstKey", SkeletalMesh\'"/Game/Skel001"\'),("secondKey", SkeletalMesh\'"/Game/Skel002"\'))')
25+
26+
ue.compile_blueprint(bp)
27+
28+
ue.open_editor_for_asset(bp)

0 commit comments

Comments
 (0)