Skip to content

Commit bfe1753

Browse files
author
Roberto De Ioris
committed
implemented get_asset() editor function
1 parent 4cd4d07 commit bfe1753

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Source/PythonConsole/Private/SPythonLog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void SPythonConsoleInputBox::OnTextCommitted(const FText& InText, ETextCommit::T
241241
OnConsoleCommandExecuted.ExecuteIfBound();
242242
return;
243243
}
244-
244+
245245
if (PyList_Check(ret)) {
246246
for (int i = 0; i < PyList_Size(ret); i++) {
247247
PyObject *item = PyList_GetItem(ret, i);

Source/UnrealEnginePython/Private/UEPyEditor.cpp

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

55
#include "Developer/AssetTools/Public/AssetToolsModule.h"
66
#include "Editor/UnrealEd/Classes/Factories/Factory.h"
7+
#include "Runtime/AssetRegistry/Public/AssetRegistryModule.h"
78

89

910
PyObject *py_unreal_engine_get_editor_world(PyObject * self, PyObject * args) {
@@ -180,5 +181,26 @@ PyObject *py_unreal_engine_message_dialog_open(PyObject * self, PyObject * args)
180181

181182
return PyLong_FromLong(ret);
182183
}
184+
185+
PyObject *py_unreal_engine_get_asset(PyObject * self, PyObject * args) {
186+
char *path;
187+
188+
if (!PyArg_ParseTuple(args, "s|get_asset", &path)) {
189+
return NULL;
190+
}
191+
192+
if (!GEditor)
193+
return PyErr_Format(PyExc_Exception, "no GEditor found");
194+
195+
FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
196+
FAssetData asset = AssetRegistryModule.Get().GetAssetByObjectPath(UTF8_TO_TCHAR(path));
197+
if (!asset.IsValid())
198+
return PyErr_Format(PyExc_Exception, "unable to find asset %s", path);
199+
ue_PyUObject *ret = ue_get_python_wrapper(asset.GetAsset());
200+
if (!ret)
201+
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
202+
Py_INCREF(ret);
203+
return (PyObject *)ret;
204+
}
183205
#endif
184206

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static PyMethodDef unreal_engine_methods[] = {
8080
{ "editor_select_actor", py_unreal_engine_editor_select_actor, METH_VARARGS, "" },
8181
{ "editor_deselect_actors", py_unreal_engine_editor_deselect_actors, METH_VARARGS, "" },
8282
{ "import_asset", py_unreal_engine_import_asset, METH_VARARGS, "" },
83+
{ "get_asset", py_unreal_engine_get_asset, METH_VARARGS, "" },
8384
#endif
8485

8586
{ "new_object", py_unreal_engine_new_object, METH_VARARGS, "" },

0 commit comments

Comments
 (0)