Skip to content

Commit d266724

Browse files
author
Roberto De Ioris
committed
improved node pin management
1 parent 4223550 commit d266724

File tree

3 files changed

+69
-18
lines changed

3 files changed

+69
-18
lines changed

Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@ PyObject *py_ue_node_allocate_default_pins(ue_PyUObject * self, PyObject * args)
489489

490490
node->AllocateDefaultPins();
491491

492-
Py_INCREF(Py_None);
493-
return Py_None;
492+
Py_RETURN_NONE;
494493
}
495494

496495
PyObject *py_ue_node_reconstruct(ue_PyUObject * self, PyObject * args)
@@ -504,8 +503,7 @@ PyObject *py_ue_node_reconstruct(ue_PyUObject * self, PyObject * args)
504503

505504
node->GetSchema()->ReconstructNode(*node);
506505

507-
Py_INCREF(Py_None);
508-
return Py_None;
506+
Py_RETURN_NONE;
509507
}
510508

511509
PyObject *py_ue_node_find_pin(ue_PyUObject * self, PyObject * args)
@@ -532,9 +530,7 @@ PyObject *py_ue_node_find_pin(ue_PyUObject * self, PyObject * args)
532530
return PyErr_Format(PyExc_Exception, "unable to find pin \"%s\"", name);
533531
}
534532

535-
PyObject *ret = py_ue_new_edgraphpin(pin);
536-
Py_INCREF(ret);
537-
return ret;
533+
return py_ue_new_edgraphpin(pin);
538534
}
539535

540536
PyObject *py_ue_node_function_entry_set_pure(ue_PyUObject * self, PyObject * args)
@@ -635,9 +631,7 @@ PyObject *py_ue_node_create_pin(ue_PyUObject * self, PyObject * args)
635631
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
636632
}
637633

638-
PyObject *ret = py_ue_new_edgraphpin(pin);
639-
Py_INCREF(ret);
640-
return ret;
634+
return py_ue_new_edgraphpin(pin);
641635
}
642636

643637

Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraphPin.cpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ static PyObject *py_ue_edgraphpin_make_link_to(ue_PyEdGraphPin *self, PyObject *
2626
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
2727
}
2828

29-
Py_INCREF(Py_None);
30-
return Py_None;
29+
Py_RETURN_NONE;
3130
}
3231

3332
static PyObject *py_ue_edgraphpin_connect(ue_PyEdGraphPin *self, PyObject * args)
@@ -54,8 +53,7 @@ static PyObject *py_ue_edgraphpin_connect(ue_PyEdGraphPin *self, PyObject * args
5453
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
5554
}
5655

57-
Py_INCREF(Py_None);
58-
return Py_None;
56+
Py_RETURN_NONE;
5957
}
6058

6159
static PyObject *py_ue_edgraphpin_break_link_to(ue_PyEdGraphPin *self, PyObject * args)
@@ -79,8 +77,7 @@ static PyObject *py_ue_edgraphpin_break_link_to(ue_PyEdGraphPin *self, PyObject
7977
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
8078
}
8179

82-
Py_INCREF(Py_None);
83-
return Py_None;
80+
Py_RETURN_NONE;
8481
}
8582

8683
static PyMethodDef ue_PyEdGraphPin_methods[] = {
@@ -175,10 +172,43 @@ static int py_ue_edgraphpin_set_default_object(ue_PyEdGraphPin *self, PyObject *
175172
return -1;
176173
}
177174

175+
static int py_ue_edgraphpin_set_category(ue_PyEdGraphPin *self, PyObject *value, void *closure)
176+
{
177+
if (value && PyUnicodeOrString_Check(value))
178+
{
179+
const char *str = UEPyUnicode_AsUTF8(value);
180+
self->pin->PinType.PinCategory = FName(UTF8_TO_TCHAR(str));
181+
return 0;
182+
}
183+
PyErr_SetString(PyExc_TypeError, "value is not a string");
184+
return -1;
185+
}
186+
187+
static int py_ue_edgraphpin_set_sub_category(ue_PyEdGraphPin *self, PyObject *value, void *closure)
188+
{
189+
if (value)
190+
{
191+
if (ue_is_pyuobject(value))
192+
{
193+
ue_PyUObject *py_obj = (ue_PyUObject *)value;
194+
self->pin->PinType.PinSubCategoryObject = py_obj->ue_object;
195+
return 0;
196+
}
197+
if (PyUnicodeOrString_Check(value))
198+
{
199+
const char *str = UEPyUnicode_AsUTF8(value);
200+
self->pin->PinType.PinSubCategory = FName(UTF8_TO_TCHAR(str));
201+
return 0;
202+
}
203+
}
204+
PyErr_SetString(PyExc_TypeError, "value is not a UObject");
205+
return -1;
206+
}
207+
178208
static PyGetSetDef ue_PyEdGraphPin_getseters[] = {
179209
{ (char*)"name", (getter)py_ue_edgraphpin_get_name, NULL, (char *)"", NULL },
180-
{ (char*)"category", (getter)py_ue_edgraphpin_get_category, NULL, (char *)"", NULL },
181-
{ (char*)"sub_category", (getter)py_ue_edgraphpin_get_sub_category, NULL, (char *)"", NULL },
210+
{ (char*)"category", (getter)py_ue_edgraphpin_get_category, (setter)py_ue_edgraphpin_set_category, (char *)"", NULL },
211+
{ (char*)"sub_category", (getter)py_ue_edgraphpin_get_sub_category, (setter)py_ue_edgraphpin_set_sub_category, (char *)"", NULL },
182212
{ (char*)"default_value", (getter)py_ue_edgraphpin_get_default_value, (setter)py_ue_edgraphpin_set_default_value, (char *)"", NULL },
183213
{ (char*)"default_text_value", (getter)py_ue_edgraphpin_get_default_text_value, (setter)py_ue_edgraphpin_set_default_text_value, (char *)"", NULL },
184214
{ (char*)"default_object", (getter)py_ue_edgraphpin_get_default_object, (setter)py_ue_edgraphpin_set_default_object, (char *)"", NULL },

examples/blueprint_dynamic_cast.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import unreal_engine as ue
2+
from unreal_engine.classes import Blueprint, K2Node_DynamicCast, Actor, Object
3+
from unreal_engine.structs import EdGraphPinType
4+
from unreal_engine.enums import EEdGraphPinDirection
5+
6+
bp_foo = ue.load_object(Blueprint, '/Game/Foo.Foo')
7+
bp_bar = ue.load_object(Blueprint, '/Game/Bar.Bar')
8+
9+
cast_node = K2Node_DynamicCast()
10+
cast_node.TargetType = bp_bar.GeneratedClass
11+
12+
graph = ue.blueprint_add_function(bp_foo, 'FooCaster')
13+
func = graph.Nodes[0]
14+
15+
pin_type = EdGraphPinType(PinCategory = 'object', PinSubCategoryObject=Actor)
16+
pin = func.node_create_pin(EEdGraphPinDirection.EGPD_Input, pin_type, 'Arg001')
17+
18+
19+
graph.graph_add_node(cast_node, 600, 0)
20+
21+
cast_node.node_find_pin('Object').category = 'object'
22+
cast_node.node_find_pin('Object').sub_category = Object
23+
24+
pin.make_link_to(cast_node.node_find_pin('Object'))
25+
func.node_find_pin('then').make_link_to(cast_node.node_find_pin('execute'))
26+
27+
ue.compile_blueprint(bp_foo)

0 commit comments

Comments
 (0)