Skip to content

Commit cfe147e

Browse files
author
Roberto De Ioris
committed
improved material scripting
1 parent 1f505f3 commit cfe147e

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

Source/UnrealEnginePython/Private/UEPyEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ PyObject *py_unreal_engine_new_object(PyObject * self, PyObject * args) {
346346

347347
FName f_name = NAME_None;
348348

349-
if (name) {
349+
if (name && strlen(name) > 0) {
350350
f_name = FName(UTF8_TO_TCHAR(name));
351351
}
352352

Source/UnrealEnginePython/Private/UEPyMaterial.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22

33
#include "UnrealEnginePythonPrivatePCH.h"
4+
#if WITH_EDITOR
5+
#include "Editor/UnrealEd/Classes/MaterialGraph/MaterialGraph.h"
6+
#include "Editor/UnrealEd/Public/Kismet2/BlueprintEditorUtils.h"
7+
#include "Editor/UnrealEd/Classes/MaterialGraph/MaterialGraphSchema.h"
8+
#endif
49

510
PyObject *py_ue_set_material_scalar_parameter(ue_PyUObject *self, PyObject * args) {
611

@@ -422,13 +427,19 @@ PyObject *py_ue_get_material_graph(ue_PyUObject *self, PyObject * args) {
422427

423428
ue_py_check(self);
424429

425-
if (!self->ue_object->IsA<UMaterialInterface>()) {
430+
if (!self->ue_object->IsA<UMaterial>()) {
426431
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInterface");
427432
}
428433

429-
UMaterialInterface *material_interface = (UMaterialInterface *)self->ue_object;
434+
UMaterial *material = (UMaterial *)self->ue_object;
435+
436+
UMaterialGraph *graph = material->MaterialGraph;
437+
if (!graph)
438+
material->MaterialGraph = (UMaterialGraph *)FBlueprintEditorUtils::CreateNewGraph(material, NAME_None, UMaterialGraph::StaticClass(), UMaterialGraphSchema::StaticClass());
439+
if (!graph)
440+
return PyErr_Format(PyExc_Exception, "Unable to retrieve/allocate MaterialGraph");
430441

431-
ue_PyUObject *ret = ue_get_python_wrapper((UObject *)material_interface->GetMaterial()->MaterialGraph);
442+
ue_PyUObject *ret = ue_get_python_wrapper(graph);
432443
if (!ret)
433444
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
434445
Py_INCREF(ret);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
341341
{ "get_py_proxy", (PyCFunction)py_ue_get_py_proxy, METH_VARARGS, "" },
342342

343343
{ "post_edit_change", (PyCFunction)py_ue_post_edit_change, METH_VARARGS, "" },
344+
{ "pre_edit_change", (PyCFunction)py_ue_pre_edit_change, METH_VARARGS, "" },
344345

345346
#if WITH_EDITOR
346347
{ "save_config", (PyCFunction)py_ue_save_config, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UEPyObject.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ PyObject *py_ue_post_edit_change(ue_PyUObject *self, PyObject * args) {
141141
return Py_None;
142142
}
143143

144+
PyObject *py_ue_pre_edit_change(ue_PyUObject *self, PyObject * args) {
145+
ue_py_check(self);
146+
147+
if (!self->ue_object) {
148+
return PyErr_Format(PyExc_Exception, "uobject is not valid");
149+
}
150+
#if WITH_EDITOR
151+
self->ue_object->PreEditChange(nullptr);
152+
#endif
153+
Py_INCREF(Py_None);
154+
return Py_None;
155+
}
156+
144157

145158
#if WITH_EDITOR
146159
PyObject *py_ue_set_metadata(ue_PyUObject * self, PyObject * args) {

Source/UnrealEnginePython/Private/UEPyObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ PyObject *py_ue_functions(ue_PyUObject *, PyObject *);
4848
PyObject *py_ue_broadcast(ue_PyUObject *, PyObject *);
4949

5050
PyObject *py_ue_post_edit_change( ue_PyUObject *, PyObject * );
51+
PyObject *py_ue_pre_edit_change(ue_PyUObject *, PyObject *);
5152

5253

5354
#if WITH_EDITOR

0 commit comments

Comments
 (0)