Skip to content

Commit dc163e9

Browse files
committed
Add graph_add_node_dynamic_cast to allow creation of dynamic cast nodes by type
1 parent 8729f2c commit dc163e9

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "Runtime/Engine/Classes/EdGraph/EdGraph.h"
66
#include "Editor/BlueprintGraph/Classes/K2Node_CallFunction.h"
7+
#include "Editor/BlueprintGraph/Classes/K2Node_DynamicCast.h"
78
#include "Editor/BlueprintGraph/Classes/EdGraphSchema_K2.h"
89
#include "Editor/BlueprintGraph/Classes/K2Node_CustomEvent.h"
910
#include "Editor/BlueprintGraph/Classes/K2Node_VariableGet.h"
@@ -380,6 +381,60 @@ PyObject *py_ue_graph_add_node(ue_PyUObject * self, PyObject * args)
380381
Py_RETURN_UOBJECT(node);
381382
}
382383

384+
PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject * self, PyObject * args)
385+
{
386+
387+
ue_py_check(self);
388+
389+
PyObject *py_node_class;
390+
int x = 0;
391+
int y = 0;
392+
393+
char *metadata = nullptr;
394+
PyObject *py_data = nullptr;
395+
396+
if(!PyArg_ParseTuple(args, "O|iis:graph_add_node_dynamic_cast", &py_node_class, &x, &y, &metadata))
397+
{
398+
return nullptr;
399+
}
400+
401+
UEdGraph *graph = ue_py_check_type<UEdGraph>(self);
402+
if(!graph)
403+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
404+
405+
UClass *u_class = ue_py_check_type<UClass>(py_node_class);
406+
if(!u_class)
407+
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
408+
409+
UK2Node_DynamicCast *node = NewObject<UK2Node_DynamicCast>(graph);
410+
node->TargetType = u_class;
411+
node->SetPurity(false);
412+
node->AllocateDefaultPins();
413+
414+
node->CreateNewGuid();
415+
node->PostPlacedNewNode();
416+
node->SetFlags(RF_Transactional);
417+
node->NodePosX = x;
418+
node->NodePosY = y;
419+
420+
if(metadata == nullptr || strlen(metadata) == 0)
421+
{
422+
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
423+
}
424+
else
425+
{
426+
UEdGraphSchema_K2::SetNodeMetaData(node, FName(UTF8_TO_TCHAR(metadata)));
427+
}
428+
graph->AddNode(node);
429+
430+
if(UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
431+
{
432+
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
433+
}
434+
435+
Py_RETURN_UOBJECT(node);
436+
}
437+
383438
PyObject *py_ue_node_pins(ue_PyUObject * self, PyObject * args)
384439
{
385440

Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ PyObject *py_ue_graph_add_node_custom_event(ue_PyUObject *, PyObject *);
1313
PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject *, PyObject *);
1414
PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject *, PyObject *);
1515
PyObject *py_ue_graph_add_node(ue_PyUObject *, PyObject *);
16+
PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject *, PyObject *);
1617
PyObject *py_ue_graph_add_node_event(ue_PyUObject *, PyObject *);
1718

1819
PyObject *py_ue_graph_get_good_place_for_new_node(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
576576
{ "graph_add_node_variable_set", (PyCFunction)py_ue_graph_add_node_variable_set, METH_VARARGS, "" },
577577

578578
{ "graph_add_node", (PyCFunction)py_ue_graph_add_node, METH_VARARGS, "" },
579+
{ "graph_add_node_dynamic_cast", (PyCFunction)py_ue_graph_add_node_dynamic_cast, METH_VARARGS, "" },
579580
{ "graph_add_node_event", (PyCFunction)py_ue_graph_add_node_event, METH_VARARGS, "" },
580581
{ "graph_get_good_place_for_new_node", (PyCFunction)py_ue_graph_get_good_place_for_new_node, METH_VARARGS, "" },
581582

0 commit comments

Comments
 (0)