Skip to content

Commit 4dbf21c

Browse files
author
Roberto De Ioris
committed
added is_loading_assets() and wait_for_assets()
1 parent 7765c7b commit 4dbf21c

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "Wrappers/UEPyIAssetEditorInstance.h"
3737
#include "Editor/MainFrame/Public/Interfaces/IMainFrameModule.h"
3838

39+
#include "Runtime/Core/Public/HAL/ThreadHeartBeat.h"
40+
3941
#include "UEPyIPlugin.h"
4042

4143
PyObject *py_unreal_engine_editor_play_in_viewport(PyObject * self, PyObject * args)
@@ -541,6 +543,35 @@ PyObject *py_unreal_engine_get_asset(PyObject * self, PyObject * args)
541543
Py_RETURN_UOBJECT(asset.GetAsset());
542544
}
543545

546+
PyObject *py_unreal_engine_is_loading_assets(PyObject * self, PyObject * args)
547+
{
548+
if (!GEditor)
549+
return PyErr_Format(PyExc_Exception, "no GEditor found");
550+
551+
FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
552+
if (AssetRegistryModule.Get().IsLoadingAssets())
553+
Py_RETURN_TRUE;
554+
Py_RETURN_FALSE;
555+
}
556+
557+
PyObject *py_unreal_engine_wait_for_assets(PyObject * self, PyObject * args)
558+
{
559+
if (!GEditor)
560+
return PyErr_Format(PyExc_Exception, "no GEditor found");
561+
562+
FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
563+
while (AssetRegistryModule.Get().IsLoadingAssets())
564+
{
565+
Py_BEGIN_ALLOW_THREADS;
566+
AssetRegistryModule.Get().Tick(-1.0f);
567+
FThreadHeartBeat::Get().HeartBeat();
568+
FPlatformProcess::SleepNoStats(0.0001f);
569+
Py_END_ALLOW_THREADS;
570+
}
571+
572+
Py_RETURN_NONE;
573+
}
574+
544575
PyObject *py_unreal_engine_find_asset(PyObject * self, PyObject * args)
545576
{
546577
char *path;
@@ -1938,7 +1969,7 @@ PyObject *py_unreal_engine_add_level_to_world(PyObject *self, PyObject * args)
19381969
if (!PyArg_ParseTuple(args, "Os|O:add_level_to_world", &py_world, &name, &py_bool))
19391970
{
19401971
return NULL;
1941-
}
1972+
}
19421973

19431974
UWorld *u_world = ue_py_check_type<UWorld>(py_world);
19441975
if (!u_world)
@@ -1955,7 +1986,7 @@ PyObject *py_unreal_engine_add_level_to_world(PyObject *self, PyObject * args)
19551986
streaming_mode_class = ULevelStreamingAlwaysLoaded::StaticClass();
19561987
}
19571988

1958-
1989+
19591990

19601991
#if ENGINE_MINOR_VERSION >= 17
19611992
ULevelStreaming *level_streaming = EditorLevelUtils::AddLevelToWorld(u_world, UTF8_TO_TCHAR(name), streaming_mode_class);
@@ -1972,7 +2003,7 @@ PyObject *py_unreal_engine_add_level_to_world(PyObject *self, PyObject * args)
19722003
#endif
19732004

19742005
Py_RETURN_UOBJECT(level_streaming);
1975-
}
2006+
}
19762007

19772008
PyObject *py_unreal_engine_move_selected_actors_to_level(PyObject *self, PyObject * args)
19782009
{
@@ -2477,7 +2508,7 @@ PyObject *py_unreal_engine_export_assets(PyObject * self, PyObject * args)
24772508
if (!py_iter)
24782509
{
24792510
return PyErr_Format(PyExc_Exception, "argument is not an iterable of UObject");
2480-
}
2511+
}
24812512

24822513
while (PyObject *py_item = PyIter_Next(py_iter))
24832514
{

Source/UnrealEnginePython/Private/UEPyEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ PyObject *py_unreal_engine_editor_deselect_actors(PyObject *, PyObject *);
1313
PyObject *py_unreal_engine_editor_select_actor(PyObject *, PyObject *);
1414
PyObject *py_unreal_engine_import_asset(PyObject *, PyObject *);
1515
PyObject *py_unreal_engine_get_asset(PyObject *, PyObject *);
16+
PyObject *py_unreal_engine_is_loading_assets(PyObject *, PyObject *);
17+
PyObject *py_unreal_engine_wait_for_assets(PyObject *, PyObject *);
1618
PyObject *py_unreal_engine_find_asset(PyObject *, PyObject *);
1719
PyObject *py_unreal_engine_delete_object(PyObject *, PyObject *);
1820
PyObject *py_unreal_engine_get_assets(PyObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ static PyMethodDef unreal_engine_methods[] = {
310310
{ "get_selected_assets", py_unreal_engine_get_selected_assets, METH_VARARGS, "" },
311311
{ "get_assets_by_class", py_unreal_engine_get_assets_by_class, METH_VARARGS, "" },
312312

313+
{ "is_loading_assets", py_unreal_engine_is_loading_assets, METH_VARARGS, "" },
314+
{ "wait_for_assets", py_unreal_engine_wait_for_assets, METH_VARARGS, "" },
315+
313316
{ "sync_browser_to_assets", py_unreal_engine_editor_sync_browser_to_assets, METH_VARARGS, "" },
314317

315318
{ "get_asset_referencers", py_unreal_engine_get_asset_referencers, METH_VARARGS, "" },

0 commit comments

Comments
 (0)