Skip to content

Commit f9b16b9

Browse files
author
Roberto De Ioris
committed
added editor_on_asset_post_import, 20tab#71
1 parent 50cb245 commit f9b16b9

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ PyObject *py_unreal_engine_import_asset(PyObject * self, PyObject * args) {
141141
}
142142
else {
143143
return PyErr_Format(PyExc_Exception, "uobject is not a Class");
144-
}
144+
}
145145
}
146146
else if (PyUnicodeOrString_Check(obj)) {
147147
char *class_name = PyUnicode_AsUTF8(obj);
@@ -156,8 +156,8 @@ PyObject *py_unreal_engine_import_asset(PyObject * self, PyObject * args) {
156156
else {
157157
return PyErr_Format(PyExc_Exception, "invalid uobject");
158158
}
159-
160-
159+
160+
161161
if (factory_class) {
162162
factory = NewObject<UFactory>(GetTransientPackage(), factory_class);
163163
if (!factory) {
@@ -179,7 +179,7 @@ PyObject *py_unreal_engine_import_asset(PyObject * self, PyObject * args) {
179179
Py_INCREF(ret);
180180
return (PyObject *)ret;
181181
}
182-
182+
183183

184184
Py_INCREF(Py_None);
185185
return Py_None;
@@ -593,7 +593,7 @@ PyObject *py_unreal_engine_add_component_to_blueprint(PyObject * self, PyObject
593593
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
594594
Py_INCREF(ret);
595595
return (PyObject *)ret;
596-
596+
597597
}
598598

599599
PyObject *py_unreal_engine_blueprint_add_member_variable(PyObject * self, PyObject * args) {
@@ -659,5 +659,22 @@ PyObject *py_unreal_engine_blueprint_add_new_timeline(PyObject * self, PyObject
659659
return (PyObject *)ret;
660660
}
661661

662+
PyObject *py_unreal_engine_editor_on_asset_post_import(PyObject * self, PyObject * args) {
663+
PyObject *py_callable;
664+
if (!PyArg_ParseTuple(args, "O:editor_on_asset_post_import", &py_callable)) {
665+
return NULL;
666+
}
667+
668+
if (!PyCallable_Check(py_callable))
669+
return PyErr_Format(PyExc_Exception, "object is not a callable");
670+
671+
UPythonDelegate *py_delegate = NewObject<UPythonDelegate>();
672+
py_delegate->SetPyCallable(py_callable);
673+
py_delegate->AddToRoot();
674+
FEditorDelegates::OnAssetPostImport.AddUObject(py_delegate, &UPythonDelegate::PyFOnAssetPostImport);
675+
Py_INCREF(Py_None);
676+
return Py_None;
677+
}
678+
662679
#endif
663680

Source/UnrealEnginePython/Private/UEPyEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ PyObject *py_unreal_engine_blueprint_add_member_variable(PyObject *, PyObject *)
3030
PyObject *py_unreal_engine_blueprint_add_new_timeline(PyObject *, PyObject *);
3131

3232
PyObject *py_unreal_engine_editor_play(PyObject *, PyObject *);
33+
PyObject *py_unreal_engine_editor_on_asset_post_import(PyObject *, PyObject *);
3334

3435
#endif

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ static PyMethodDef unreal_engine_methods[] = {
158158
{ "slate_window", py_unreal_engine_slate_window, METH_VARARGS, "" },
159159
{ "slate_button", py_unreal_engine_slate_button, METH_VARARGS, "" },
160160
{ "get_editor_window", py_unreal_engine_get_editor_window, METH_VARARGS, "" },
161+
162+
{ "editor_on_asset_post_import", py_unreal_engine_editor_on_asset_post_import, METH_VARARGS, "" },
161163
#endif
162164

163165
{ "new_object", py_unreal_engine_new_object, METH_VARARGS, "" },

Source/UnrealEnginePython/Public/PythonDelegate.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ bool UPythonDelegate::Tick(float DeltaTime)
109109
return false;
110110
}
111111

112+
#if WITH_EDITOR
113+
void UPythonDelegate::PyFOnAssetPostImport(UFactory *factory, UObject *u_object)
114+
{
115+
FScopePythonGIL gil;
116+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"OO", ue_get_python_wrapper((UObject *)factory), ue_get_python_wrapper(u_object));
117+
if (!ret) {
118+
unreal_engine_py_log_error();
119+
return;
120+
}
121+
Py_DECREF(ret);
122+
}
123+
#endif
124+
125+
112126
UPythonDelegate::~UPythonDelegate()
113127
{
114128
FScopePythonGIL gil;

Source/UnrealEnginePython/Public/PythonDelegate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class UPythonDelegate : public UObject
2020

2121
bool Tick(float DeltaTime);
2222

23+
#if WITH_EDITOR
24+
void PyFOnAssetPostImport(UFactory *factory, UObject *u_object);
25+
#endif
26+
2327
private:
2428
UFunction *signature;
2529
bool signature_set;

0 commit comments

Comments
 (0)