PyObject *py_ue_get_actor_component(ue_PyUObject * self, PyObject * args) { ue_py_check(self); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject"); char *name; if (!PyArg_ParseTuple(args, "s:get_actor_component", &name)) { return NULL; } for (UActorComponent *component : actor->GetComponents()) { if (component->GetName().Equals(UTF8_TO_TCHAR(name))) { ue_PyUObject *py_obj = ue_get_python_wrapper(component); if (!py_obj) return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state"); Py_INCREF(py_obj); return (PyObject *)py_obj; } } Py_INCREF(Py_None); return Py_None; }
PyObject *py_ue_actor_destroy_component(ue_PyUObject * self, PyObject * args) { ue_py_check(self); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject"); PyObject *py_component; if (!PyArg_ParseTuple(args, "O:actor_destroy_component", &py_component)) { return NULL; } UActorComponent *component = ue_py_check_type<UActorComponent>(py_component); if (!component) return PyErr_Format(PyExc_Exception, "argument is not a UActorComponent"); #if ENGINE_MINOR_VERSION >= 17 component->DestroyComponent(); #else actor->K2_DestroyComponent(component); #endif Py_INCREF(Py_None); return Py_None; }
PyObject *py_ue_get_actor_component(ue_PyUObject * self, PyObject * args) { ue_py_check(self); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject"); char *name; if (!PyArg_ParseTuple(args, "s:get_actor_component", &name)) { return NULL; } for (UActorComponent *component : actor->GetComponents()) { if (component->GetName().Equals(UTF8_TO_TCHAR(name))) { Py_RETURN_UOBJECT(component); } } Py_RETURN_NONE; }
PyObject *py_ue_get_actor_velocity(ue_PyUObject *self, PyObject * args) { ue_py_check(self); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component"); return py_ue_new_fvector(actor->GetVelocity()); }
PyObject *py_ue_get_actor_components_by_type(ue_PyUObject * self, PyObject * args) { ue_py_check(self); PyObject *obj; if (!PyArg_ParseTuple(args, "O:get_actor_components_by_type", &obj)) { return NULL; } ue_PyUObject *py_obj = nullptr; if (ue_is_pyuobject(obj)) { py_obj = (ue_PyUObject *)obj; } // shortcut for finding class by string else if (PyUnicodeOrString_Check(obj)) { char *class_name = PyUnicode_AsUTF8(obj); UClass *u_class = FindObject<UClass>(ANY_PACKAGE, UTF8_TO_TCHAR(class_name)); if (u_class) { py_obj = ue_get_python_uobject(u_class); } } if (!py_obj) return PyErr_Format(PyExc_Exception, "argument is not a UObject"); if (!py_obj->ue_object->IsA<UClass>()) return PyErr_Format(PyExc_Exception, "argument is not a UClass"); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "uobject is not an AActor"); PyObject *components = PyList_New(0); for (UActorComponent *component : actor->GetComponentsByClass((UClass *)py_obj->ue_object)) { ue_PyUObject *item = ue_get_python_uobject(component); if (item) PyList_Append(components, (PyObject *)item); } return components; }
PyObject *py_ue_get_editor_world_counterpart_actor(ue_PyUObject * self, PyObject * args) { ue_py_check(self); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "cannot retrieve actor from UObject"); AActor *editor_actor = EditorUtilities::GetEditorWorldCounterpartActor(actor); if (!editor_actor) return PyErr_Format(PyExc_Exception, "unable to retrieve editor counterpart actor"); Py_RETURN_UOBJECT(editor_actor); }
PyObject *py_ue_get_actor_component_by_type(ue_PyUObject * self, PyObject * args) { ue_py_check(self); PyObject *obj; if (!PyArg_ParseTuple(args, "O:get_actor_component_by_type", &obj)) { return NULL; } ue_PyUObject *py_obj = nullptr; if (ue_is_pyuobject(obj)) { py_obj = (ue_PyUObject *)obj; } // shortcut for finding class by string else if (PyUnicodeOrString_Check(obj)) { char *class_name = PyUnicode_AsUTF8(obj); UClass *u_class = FindObject<UClass>(ANY_PACKAGE, UTF8_TO_TCHAR(class_name)); if (u_class) { py_obj = ue_get_python_wrapper(u_class); } } if (!py_obj) return PyErr_Format(PyExc_Exception, "argument is not a UObject"); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "uobject is not an AActor"); if (!py_obj->ue_object->IsA<UClass>()) return PyErr_Format(PyExc_Exception, "argument is not a UClass"); UActorComponent *component = actor->GetComponentByClass((UClass *)py_obj->ue_object); if (component) { PyObject *ret = (PyObject *)ue_get_python_wrapper(component); if (!ret) return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); Py_INCREF(ret); return ret; } Py_INCREF(Py_None); return Py_None; }
PyObject *py_ue_get_overlapping_actors(ue_PyUObject * self, PyObject * args) { ue_py_check(self); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "cannot retrieve actor from UObject"); PyObject *class_filter = nullptr; if (!PyArg_ParseTuple(args, "|O:get_overlapping_actors", &class_filter)) { return NULL; } UClass *filtering = AActor::StaticClass(); if (class_filter) { if (!ue_is_pyuobject(class_filter)) return PyErr_Format(PyExc_Exception, "argument is not a UObject"); ue_PyUObject *py_obj = (ue_PyUObject *)class_filter; if (!py_obj->ue_object->IsA((UClass *)py_obj->ue_object)) return PyErr_Format(PyExc_Exception, "argument is not a UClass"); filtering = (UClass *)py_obj->ue_object; } PyObject *py_overlapping_actors = PyList_New(0); TArray<AActor *> overalpping_actors; actor->GetOverlappingActors(overalpping_actors, filtering); for (AActor *overlapping_actor : overalpping_actors) { ue_PyUObject *item = ue_get_python_uobject(overlapping_actor); if (item) { PyList_Append(py_overlapping_actors, (PyObject *)item); } } return py_overlapping_actors; }
PyObject *py_ue_get_actor_root_component(ue_PyUObject * self, PyObject * args) { ue_py_check(self); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject"); UActorComponent *component = actor->GetRootComponent(); if (component) { Py_RETURN_UOBJECT(component); } Py_RETURN_NONE; }
PyObject *py_ue_set_actor_label(ue_PyUObject *self, PyObject * args) { ue_py_check(self); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject"); char *label; if (!PyArg_ParseTuple(args, "s:set_actor_label", &label)) { return NULL; } actor->SetActorLabel(UTF8_TO_TCHAR(label), true); Py_INCREF(Py_None); return Py_None; }
PyObject *py_ue_actor_components(ue_PyUObject * self, PyObject * args) { ue_py_check(self); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject"); PyObject *ret = PyList_New(0); for (UActorComponent *component : actor->GetComponents()) { ue_PyUObject *py_obj = ue_get_python_wrapper(component); if (!py_obj) continue; PyList_Append(ret, (PyObject *)py_obj); } return ret; }