Skip to content

Commit 80927a9

Browse files
author
Roberto De Ioris
committed
added (broken) graph_add_node_variable_get, graph_add_node_variable_set
1 parent fa16fc3 commit 80927a9

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

Source/UnrealEnginePython/Private/UEPyEdGraph.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include "Editor/BlueprintGraph/Classes/K2Node_CallFunction.h"
77
#include "Editor/BlueprintGraph/Classes/EdGraphSchema_K2.h"
88
#include "Editor/BlueprintGraph/Classes/K2Node_CustomEvent.h"
9+
#include "Editor/BlueprintGraph/Classes/K2Node_VariableGet.h"
10+
#include "Editor/BlueprintGraph/Classes/K2Node_VariableSet.h"
11+
#include "Editor/UnrealEd/Public/Kismet2/BlueprintEditorUtils.h"
912

1013
PyObject *py_ue_graph_add_node_call_function(ue_PyUObject * self, PyObject * args) {
1114

@@ -98,5 +101,105 @@ PyObject *py_ue_graph_add_node_custom_event(ue_PyUObject * self, PyObject * args
98101
Py_INCREF(ret);
99102
return ret;
100103

104+
}
105+
106+
PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject * self, PyObject * args) {
107+
108+
ue_py_check(self);
109+
110+
char *name = nullptr;
111+
PyObject *py_struct = nullptr;
112+
int x = 0;
113+
int y = 0;
114+
if (!PyArg_ParseTuple(args, "s|Oii:graph_add_node_variable_get", &name, &py_struct, &x, &y)) {
115+
return NULL;
116+
}
117+
118+
if (!self->ue_object->IsA<UEdGraph>()) {
119+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
120+
}
121+
122+
UEdGraph *graph = (UEdGraph *)self->ue_object;
123+
UStruct *u_struct = nullptr;
124+
125+
if (py_struct && py_struct != Py_None) {
126+
if (!ue_is_pyuobject(py_struct)) {
127+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
128+
}
129+
ue_PyUObject *ue_py_struct = (ue_PyUObject *)py_struct;
130+
if (!ue_py_struct->ue_object->IsA<UStruct>()) {
131+
return PyErr_Format(PyExc_Exception, "argument is not a UStruct");
132+
}
133+
u_struct = (UStruct *)ue_py_struct->ue_object;
134+
}
135+
136+
UK2Node_VariableGet *node = NewObject<UK2Node_VariableGet>(graph);
137+
138+
node->CreateNewGuid();
139+
node->PostPlacedNewNode();
140+
node->SetFlags(RF_Transactional);
141+
node->AllocateDefaultPins();
142+
node->NodePosX = x;
143+
node->NodePosY = y;
144+
UEdGraphSchema_K2::ConfigureVarNode(node, FName(UTF8_TO_TCHAR(name)), u_struct, FBlueprintEditorUtils::FindBlueprintForGraph(graph));
145+
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
146+
graph->AddNode(node);
147+
148+
PyObject *ret = (PyObject *)ue_get_python_wrapper(node);
149+
if (!ret)
150+
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
151+
Py_INCREF(ret);
152+
return ret;
153+
154+
}
155+
156+
PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject * self, PyObject * args) {
157+
158+
ue_py_check(self);
159+
160+
char *name = nullptr;
161+
PyObject *py_struct = nullptr;
162+
int x = 0;
163+
int y = 0;
164+
if (!PyArg_ParseTuple(args, "s|Oii:graph_add_node_variable_set", &name, &py_struct, &x, &y)) {
165+
return NULL;
166+
}
167+
168+
if (!self->ue_object->IsA<UEdGraph>()) {
169+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
170+
}
171+
172+
UEdGraph *graph = (UEdGraph *)self->ue_object;
173+
UStruct *u_struct = nullptr;
174+
175+
if (py_struct && py_struct != Py_None) {
176+
if (!ue_is_pyuobject(py_struct)) {
177+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
178+
}
179+
ue_PyUObject *ue_py_struct = (ue_PyUObject *)py_struct;
180+
if (!ue_py_struct->ue_object->IsA<UStruct>()) {
181+
return PyErr_Format(PyExc_Exception, "argument is not a UStruct");
182+
}
183+
u_struct = (UStruct *)ue_py_struct->ue_object;
184+
}
185+
186+
UK2Node_VariableSet *node = NewObject<UK2Node_VariableSet>(graph);
187+
188+
node->CreateNewGuid();
189+
node->PostPlacedNewNode();
190+
node->SetFlags(RF_Transactional);
191+
node->AllocateDefaultPins();
192+
node->NodePosX = x;
193+
node->NodePosY = y;
194+
UEdGraphSchema_K2::ConfigureVarNode(node, FName(UTF8_TO_TCHAR(name)), u_struct, FBlueprintEditorUtils::FindBlueprintForGraph(graph));
195+
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
196+
graph->AddNode(node);
197+
198+
PyObject *ret = (PyObject *)ue_get_python_wrapper(node);
199+
if (!ret)
200+
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
201+
Py_INCREF(ret);
202+
return ret;
203+
101204
}
102205
#endif

Source/UnrealEnginePython/Private/UEPyEdGraph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
#if WITH_EDITOR
88
PyObject *py_ue_graph_add_node_call_function(ue_PyUObject *, PyObject *);
99
PyObject *py_ue_graph_add_node_custom_event(ue_PyUObject *, PyObject *);
10+
PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject *, PyObject *);
11+
PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject *, PyObject *);
1012
#endif

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ static PyMethodDef ue_PyUObject_methods[] = {
300300

301301
{ "graph_add_node_call_function", (PyCFunction)py_ue_graph_add_node_call_function, METH_VARARGS, "" },
302302
{ "graph_add_node_custom_event", (PyCFunction)py_ue_graph_add_node_custom_event, METH_VARARGS, "" },
303+
{ "graph_add_node_variable_get", (PyCFunction)py_ue_graph_add_node_variable_get, METH_VARARGS, "" },
304+
{ "graph_add_node_variable_set", (PyCFunction)py_ue_graph_add_node_variable_set, METH_VARARGS, "" },
303305
#endif
304306

305307
{ "is_rooted", (PyCFunction)py_ue_is_rooted, METH_VARARGS, "" },
@@ -528,7 +530,7 @@ void ue_pydelegates_cleanup(ue_PyUObject *self) {
528530
UE_LOG(LogPython, Warning, TEXT("Removing UPythonDelegate %p from ue_PyUObject %p mapped to UObject %p"), py_delegate, self, self->ue_object);
529531
#endif
530532
py_delegate->RemoveFromRoot();
531-
}
533+
}
532534
}
533535
self->python_delegates_gc->clear();
534536
delete self->python_delegates_gc;

0 commit comments

Comments
 (0)