Skip to content

Commit 9f42f93

Browse files
author
Roberto De Ioris
committed
added get_display_name() shortcut
1 parent e1b1592 commit 9f42f93

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
422422

423423

424424
{ "get_name", (PyCFunction)py_ue_get_name, METH_VARARGS, "" },
425+
{ "get_display_name", (PyCFunction)py_ue_get_display_name, METH_VARARGS, "" },
425426
{ "get_path_name", (PyCFunction)py_ue_get_path_name, METH_VARARGS, "" },
426427
{ "get_full_name", (PyCFunction)py_ue_get_full_name, METH_VARARGS, "" },
427428

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,24 @@ PyObject *py_ue_get_name(ue_PyUObject *self, PyObject * args) {
395395
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->ue_object->GetName())));
396396
}
397397

398+
PyObject *py_ue_get_display_name(ue_PyUObject *self, PyObject * args) {
399+
400+
ue_py_check(self);
401+
402+
#if WITH_EDITOR
403+
if (AActor *actor = ue_py_check_type<AActor>(self)) {
404+
return PyUnicode_FromString(TCHAR_TO_UTF8(*actor->GetActorLabel()));
405+
}
406+
#endif
407+
408+
if (UActorComponent *component = ue_py_check_type<UActorComponent>(self)) {
409+
return PyUnicode_FromString(TCHAR_TO_UTF8(*component->GetReadableName()));
410+
}
411+
412+
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->ue_object->GetName())));
413+
}
414+
415+
398416
PyObject *py_ue_get_full_name(ue_PyUObject *self, PyObject * args) {
399417

400418
ue_py_check(self);
@@ -485,7 +503,7 @@ PyObject *py_ue_enum_names(ue_PyUObject *self, PyObject * args) {
485503
#endif
486504
PyList_Append(ret, py_long);
487505
Py_DECREF(py_long);
488-
}
506+
}
489507
return ret;
490508
}
491509

Source/UnrealEnginePython/Private/UObject/UEPyObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PyObject *py_ue_is_child_of(ue_PyUObject *, PyObject *);
1010
PyObject *py_ue_call_function(ue_PyUObject *, PyObject *, PyObject *);
1111
PyObject *py_ue_find_function(ue_PyUObject *, PyObject *);
1212
PyObject *py_ue_get_name(ue_PyUObject *, PyObject * args);
13+
PyObject *py_ue_get_display_name(ue_PyUObject *, PyObject * args);
1314
PyObject *py_ue_set_name(ue_PyUObject *, PyObject * args);
1415
PyObject *py_ue_get_full_name(ue_PyUObject *, PyObject *);
1516
PyObject *py_ue_get_path_name(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)