Skip to content

Commit 7874b1c

Browse files
author
Roberto De Ioris
committed
added get_levels()
1 parent badad57 commit 7874b1c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ static PyMethodDef ue_PyUObject_methods[] = {
380380
{ "set_view_target", (PyCFunction)py_ue_set_view_target, METH_VARARGS, "" },
381381
{ "get_world_delta_seconds", (PyCFunction)py_ue_get_world_delta_seconds, METH_VARARGS, "" },
382382

383+
{ "get_levels", (PyCFunction)py_ue_get_levels, METH_VARARGS, "" },
384+
383385
{ "add_actor_component", (PyCFunction)py_ue_add_actor_component, METH_VARARGS, "" },
384386
{ "add_actor_root_component", (PyCFunction)py_ue_add_actor_root_component, METH_VARARGS, "" },
385387
{ "get_actor_component_by_type", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UEPyWorld.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,23 @@ PyObject *py_ue_get_world_delta_seconds(ue_PyUObject * self, PyObject * args) {
177177

178178
return Py_BuildValue("f", UGameplayStatics::GetWorldDeltaSeconds(world));
179179
}
180+
181+
PyObject *py_ue_get_levels(ue_PyUObject * self, PyObject * args) {
182+
183+
ue_py_check(self);
184+
185+
UWorld *world = ue_get_uworld(self);
186+
if (!world)
187+
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
188+
189+
PyObject *ret = PyList_New(0);
190+
191+
for (ULevel *level : world->GetLevels() ) {
192+
ue_PyUObject *py_obj = ue_get_python_wrapper(level);
193+
if (!py_obj)
194+
continue;
195+
PyList_Append(ret, (PyObject *)py_obj);
196+
197+
}
198+
return ret;
199+
}

Source/UnrealEnginePython/Private/UEPyWorld.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ PyObject *py_ue_get_world(ue_PyUObject *, PyObject *);
1717
PyObject *py_ue_has_world(ue_PyUObject *, PyObject *);
1818

1919
PyObject *py_ue_set_view_target(ue_PyUObject *, PyObject *);
20-
PyObject *py_ue_get_world_delta_seconds(ue_PyUObject *, PyObject *);
20+
PyObject *py_ue_get_world_delta_seconds(ue_PyUObject *, PyObject *);
21+
22+
PyObject *py_ue_get_levels(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)