Skip to content

Commit 99059ae

Browse files
author
Roberto De Ioris
committed
finalized tagging api
1 parent 8a7fffb commit 99059ae

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
769769
#pragma warning(suppress: 4191)
770770
{ "actor_spawn", (PyCFunction)py_ue_actor_spawn, METH_VARARGS | METH_KEYWORDS, "" },
771771
{ "actor_has_tag", (PyCFunction)py_ue_actor_has_tag, METH_VARARGS, "" },
772+
{ "component_has_tag", (PyCFunction)py_ue_component_has_tag, METH_VARARGS, "" },
772773
{ "get_actor_bounds", (PyCFunction)py_ue_get_actor_bounds, METH_VARARGS, "" },
773774

774775
{ "line_trace_single_by_channel", (PyCFunction)py_ue_line_trace_single_by_channel, METH_VARARGS, "" },
@@ -799,11 +800,17 @@ static PyMethodDef ue_PyUObject_methods[] = {
799800
{ "get_actor_root_component", (PyCFunction)py_ue_get_actor_root_component, METH_VARARGS, "" },
800801
{ "add_actor_root_component", (PyCFunction)py_ue_add_actor_root_component, METH_VARARGS, "" },
801802
{ "get_actor_component_by_type", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },
803+
{ "get_actor_component_by_class", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },
802804
{ "get_component_by_type", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },
805+
{ "get_component_by_class", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },
803806
{ "get_component", (PyCFunction)py_ue_get_actor_component, METH_VARARGS, "" },
804807
{ "get_actor_component", (PyCFunction)py_ue_get_actor_component, METH_VARARGS, "" },
805808
{ "get_actor_components_by_type", (PyCFunction)py_ue_get_actor_components_by_type, METH_VARARGS, "" },
806809
{ "get_components_by_type", (PyCFunction)py_ue_get_actor_components_by_type, METH_VARARGS, "" },
810+
{ "get_actor_components_by_class", (PyCFunction)py_ue_get_actor_components_by_type, METH_VARARGS, "" },
811+
{ "get_components_by_class", (PyCFunction)py_ue_get_actor_components_by_type, METH_VARARGS, "" },
812+
{ "get_actor_components_by_tag", (PyCFunction)py_ue_get_actor_components_by_tag, METH_VARARGS, "" },
813+
{ "get_components_by_tag", (PyCFunction)py_ue_get_actor_components_by_tag, METH_VARARGS, "" },
807814

808815
{ "add_python_component", (PyCFunction)py_ue_add_python_component, METH_VARARGS, "" },
809816

Source/UnrealEnginePython/Private/UObject/UEPyActor.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ PyObject *py_ue_actor_has_tag(ue_PyUObject * self, PyObject * args)
2727
Py_RETURN_FALSE;
2828
}
2929

30+
PyObject *py_ue_component_has_tag(ue_PyUObject * self, PyObject * args)
31+
{
32+
33+
ue_py_check(self);
34+
35+
char *tag;
36+
if (!PyArg_ParseTuple(args, "s:component_has_tag", &tag))
37+
{
38+
return nullptr;
39+
}
40+
41+
UActorComponent *component = ue_py_check_type<UActorComponent>(self);
42+
if (!component)
43+
return PyErr_Format(PyExc_Exception, "uobject is not an UActorComponent");
44+
45+
if (component->ComponentHasTag(FName(UTF8_TO_TCHAR(tag))))
46+
{
47+
Py_RETURN_TRUE;
48+
}
49+
50+
Py_RETURN_FALSE;
51+
}
52+
3053
PyObject *py_ue_actor_begin_play(ue_PyUObject * self, PyObject * args)
3154
{
3255

@@ -692,6 +715,51 @@ PyObject *py_ue_get_actor_components_by_type(ue_PyUObject * self, PyObject * arg
692715

693716
}
694717

718+
PyObject *py_ue_get_actor_components_by_tag(ue_PyUObject * self, PyObject * args)
719+
{
720+
721+
ue_py_check(self);
722+
723+
char *tag;
724+
PyObject *py_uclass = nullptr;
725+
if (!PyArg_ParseTuple(args, "s|O:get_actor_components_by_tag", &tag, &py_uclass))
726+
{
727+
return nullptr;
728+
}
729+
730+
AActor *actor = ue_get_actor(self);
731+
if (!actor)
732+
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
733+
734+
PyObject *components = PyList_New(0);
735+
736+
UClass *u_class = UActorComponent::StaticClass();
737+
738+
if (py_uclass)
739+
{
740+
u_class = ue_py_check_type<UClass>(py_uclass);
741+
if (!u_class)
742+
{
743+
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
744+
}
745+
746+
if (!u_class->IsChildOf<UActorComponent>())
747+
{
748+
return PyErr_Format(PyExc_Exception, "argument is not a UClass inheriting from UActorComponent");
749+
}
750+
}
751+
752+
for (UActorComponent *component : actor->GetComponentsByTag(u_class, FName(UTF8_TO_TCHAR(tag))))
753+
{
754+
ue_PyUObject *item = ue_get_python_uobject(component);
755+
if (item)
756+
PyList_Append(components, (PyObject *)item);
757+
}
758+
759+
return components;
760+
761+
}
762+
695763

696764
PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args, PyObject *kwargs)
697765
{
@@ -790,7 +858,7 @@ PyObject *py_ue_get_overlapping_actors(ue_PyUObject * self, PyObject * args)
790858

791859
ue_py_check(self);
792860

793-
861+
794862
PyObject *class_filter = nullptr;
795863
if (!PyArg_ParseTuple(args, "|O:get_overlapping_actors", &class_filter))
796864
{

Source/UnrealEnginePython/Private/UObject/UEPyActor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "UObject/UObjectThreadContext.h"
1717

1818
PyObject *py_ue_actor_has_tag(ue_PyUObject *, PyObject *);
19+
PyObject *py_ue_component_has_tag(ue_PyUObject *, PyObject *);
1920
PyObject *py_ue_actor_begin_play(ue_PyUObject *, PyObject *);
2021
PyObject *py_ue_get_actor_bounds(ue_PyUObject *, PyObject *);
2122
PyObject *py_ue_get_actor_component(ue_PyUObject *, PyObject *);
@@ -37,6 +38,7 @@ PyObject *py_ue_add_actor_root_component(ue_PyUObject *, PyObject *);
3738
PyObject *py_ue_actor_has_component_of_type(ue_PyUObject *, PyObject *);
3839
PyObject *py_ue_get_actor_component_by_type(ue_PyUObject *, PyObject *);
3940
PyObject *py_ue_get_actor_components_by_type(ue_PyUObject *, PyObject *);
41+
PyObject *py_ue_get_actor_components_by_tag(ue_PyUObject *, PyObject *);
4042
PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject *, PyObject *);
4143
PyObject *py_ue_get_overlapping_actors(ue_PyUObject *, PyObject *);
4244

0 commit comments

Comments
 (0)