PyObject *py_ue_set_player_hud(ue_PyUObject *self, PyObject * args) { ue_py_check(self); PyObject *py_hud; int controller_id = 0; if (!PyArg_ParseTuple(args, "O|i:set_player_hud", &py_hud, &controller_id)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); AHUD *hud = ue_py_check_type<AHUD>(py_hud); if (!hud) return PyErr_Format(PyExc_Exception, "argument is not a AHUD"); APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id); if (!controller) return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id); controller->MyHUD = hud; Py_RETURN_NONE; }
PyObject *py_ue_is_input_key_down(ue_PyUObject *self, PyObject * args) { ue_py_check(self); char *key; int controller_id = 0; if (!PyArg_ParseTuple(args, "s|i:is_input_key_down", &key, &controller_id)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id); if (!controller) return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id); if (controller->IsInputKeyDown(key)) { Py_INCREF(Py_True); return Py_True; } Py_INCREF(Py_False); return Py_False; }
PyObject *py_ue_create_player(ue_PyUObject *self, PyObject * args) { ue_py_check(self); int controller_id; PyObject *spawn_pawn; if (!PyArg_ParseTuple(args, "i|O:create_player", &controller_id, &spawn_pawn)) { return NULL; } bool b_spawn_pawn = true; if (spawn_pawn && !PyObject_IsTrue(spawn_pawn)) { b_spawn_pawn = false; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); APlayerController *controller = UGameplayStatics::CreatePlayer(world, controller_id, b_spawn_pawn); if (!controller) return PyErr_Format(PyExc_Exception, "unable to create a new player from controller %d", controller_id); return PyLong_FromLong(controller->PlayerState->PlayerId); }
PyObject *py_ue_get_player_pawn(ue_PyUObject *self, PyObject * args) { ue_py_check(self); int controller_id = 0; if (!PyArg_ParseTuple(args, "|i:get_player_pawn", &controller_id)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id); if (!controller) return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id); // the controller could not have a pawn if (!controller->GetPawn()) Py_RETURN_NONE; Py_RETURN_UOBJECT(controller->GetPawn()); }
PyObject *py_ue_find_actor_by_label(ue_PyUObject * self, PyObject * args) { ue_py_check(self); char *name; if (!PyArg_ParseTuple(args, "s:find_actor_by_label", &name)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); UObject *u_object = nullptr; for (TActorIterator<AActor> Itr(world); Itr; ++Itr) { AActor *u_obj = *Itr; if (u_obj->GetActorLabel().Equals(UTF8_TO_TCHAR(name))) { u_object = u_obj; break; } } if (u_object) { Py_RETURN_UOBJECT(u_object); } Py_RETURN_NONE; }
PyObject *py_ue_draw_debug_line(ue_PyUObject * self, PyObject * args) { ue_py_check(self); PyObject *py_obj_start; PyObject *py_obj_end; PyObject *py_color; float duration = 0; float thickness = 0; UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); if (!PyArg_ParseTuple(args, "OOO|ff:draw_debug_line", &py_obj_start, &py_obj_end, &py_color, &duration, &thickness)) { return NULL; } ue_PyFVector *start = py_ue_is_fvector(py_obj_start); ue_PyFVector *end = py_ue_is_fvector(py_obj_end); if (!start || !end) return PyErr_Format(PyExc_Exception, "start and end location must be vectors"); ue_PyFLinearColor *py_linear_color = py_ue_is_flinearcolor(py_color); if (!py_linear_color) return PyErr_Format(PyExc_Exception, "argument is not a FLinearColor"); UKismetSystemLibrary::DrawDebugLine(world, start->vec, end->vec, py_linear_color->color, duration, thickness); Py_RETURN_NONE; }
PyObject *py_ue_find_actor_by_label(ue_PyUObject * self, PyObject * args) { ue_py_check(self); char *name; if (!PyArg_ParseTuple(args, "s:find_actor_by_label", &name)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); UObject *u_object = nullptr; for (TActorIterator<AActor> Itr(world); Itr; ++Itr) { AActor *u_obj = *Itr; if (u_obj->GetActorLabel().Equals(UTF8_TO_TCHAR(name))) { u_object = u_obj; break; } } if (u_object) { ue_PyUObject *ret = ue_get_python_wrapper(u_object); if (!ret) return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state"); Py_INCREF(ret); return (PyObject *)ret; } Py_INCREF(Py_None); return Py_None; }
PyObject *py_ue_enable_mouse_over_events(ue_PyUObject * self, PyObject * args) { ue_py_check(self); bool enabled = true; PyObject *is_true = NULL; int controller_id = 0; if (!PyArg_ParseTuple(args, "|Oi:enable_mouse_over_events", &is_true, &controller_id)) { return NULL; } if (is_true && !PyObject_IsTrue(is_true)) enabled = false; UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id); if (controller) controller->bEnableMouseOverEvents = enabled; Py_INCREF(Py_None); return Py_None; }
PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject * self, PyObject * args) { ue_py_check(self); PyObject *py_obj_start; PyObject *py_obj_end; int channel; UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); if (!PyArg_ParseTuple(args, "OOi:line_trace_multi_by_channel", &py_obj_start, &py_obj_end, &channel)) { return NULL; } ue_PyFVector *start = py_ue_is_fvector(py_obj_start); ue_PyFVector *end = py_ue_is_fvector(py_obj_end); if (!start || !end) return PyErr_Format(PyExc_Exception, "start and end location must be vectors"); TArray<struct FHitResult> hits; hits.Reset(); PyObject *hits_list = PyList_New(0); bool got_hits = world->LineTraceMultiByChannel(hits, start->vec, end->vec, (ECollisionChannel)channel); if (got_hits) { for (int i = 0; i < hits.Num(); i++) { FHitResult hit = hits[i]; PyList_Append(hits_list, py_ue_new_fhitresult(hit)); } } return hits_list; }
PyObject *py_ue_get_hit_result_under_cursor(ue_PyUObject * self, PyObject * args) { ue_py_check(self); int channel; PyObject *trace_complex = nullptr; int controller_id = 0; UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); if (!PyArg_ParseTuple(args, "i|Oi:get_hit_result_under_cursor", &channel, &trace_complex, &controller_id)) { return nullptr; } bool complex = false; if (trace_complex && PyObject_IsTrue(trace_complex)) { complex = true; } APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id); if (!controller) return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id); FHitResult hit; bool got_hit = controller->GetHitResultUnderCursor((ECollisionChannel)channel, complex, hit); if (got_hit) { return py_ue_new_fhitresult(hit); } Py_RETURN_NONE; }
PyObject *py_ue_get_player_camera_manager(ue_PyUObject *self, PyObject * args) { ue_py_check(self); int controller_id = 0; if (!PyArg_ParseTuple(args, "|i:get_player_camera_manager", &controller_id)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); APlayerCameraManager *camera = UGameplayStatics::GetPlayerCameraManager(world, controller_id); if (!camera) return PyErr_Format(PyExc_Exception, "unable to retrieve camera manager for controller %d", controller_id); Py_RETURN_UOBJECT(camera); }
PyObject *py_ue_get_num_spectators(ue_PyUObject *self, PyObject * args) { ue_py_check(self); UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); #if ENGINE_MINOR_VERSION < 14 AGameMode *game_mode = world->GetAuthGameMode(); #else AGameModeBase *game_mode = world->GetAuthGameMode(); #endif if (!game_mode) return PyErr_Format(PyExc_Exception, "unable to retrieve GameMode from world"); #if ENGINE_MINOR_VERSION < 14 return PyLong_FromLong(game_mode->NumSpectators); #else return PyLong_FromLong(game_mode->GetNumSpectators()); #endif }
PyObject *py_ue_simple_move_to_location(ue_PyUObject *self, PyObject * args) { ue_py_check(self); FVector vec; if (!py_ue_vector_arg(args, vec)) return NULL; UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); APawn *pawn = nullptr; if (self->ue_object->IsA<APawn>()) { pawn = (APawn *)self->ue_object; } else if (self->ue_object->IsA<UActorComponent>()) { UActorComponent *component = (UActorComponent *)self->ue_object; AActor *actor = component->GetOwner(); if (actor) { if (actor->IsA<APawn>()) { pawn = (APawn *)actor; } } } if (!pawn) return PyErr_Format(PyExc_Exception, "uobject is not a pawn"); AController *controller = pawn->GetController(); if (!controller) return PyErr_Format(PyExc_Exception, "Pawn has no controller"); world->GetNavigationSystem()->SimpleMoveToLocation(controller, vec); Py_INCREF(Py_None); return Py_None; }
PyObject *py_ue_restart_level(ue_PyUObject *self, PyObject * args) { ue_py_check(self); int controller_id = 0; if (!PyArg_ParseTuple(args, "|i:restart_level", &controller_id)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id); if (!controller) return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id); controller->RestartLevel(); Py_RETURN_NONE; }
PyObject *py_ue_line_trace_single_by_channel(ue_PyUObject * self, PyObject * args) { ue_py_check(self); PyObject *py_obj_start; PyObject *py_obj_end; int channel; UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); if (!PyArg_ParseTuple(args, "OOi:line_trace_single_by_channel", &py_obj_start, &py_obj_end, &channel)) { return NULL; } ue_PyFVector *start = py_ue_is_fvector(py_obj_start); ue_PyFVector *end = py_ue_is_fvector(py_obj_end); if (!start || !end) return PyErr_Format(PyExc_Exception, "start and end location must be vectors"); FHitResult hit; bool got_hit = world->LineTraceSingleByChannel(hit, start->vec, end->vec, (ECollisionChannel)channel); if (got_hit) { return py_ue_new_fhitresult(hit); } Py_RETURN_NONE; }
PyObject *py_ue_is_action_pressed(ue_PyUObject *self, PyObject * args) { ue_py_check(self); char *key; int controller_id = 0; if (!PyArg_ParseTuple(args, "s|i:is_action_pressed", &key, &controller_id)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id); if (!controller) return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id); UPlayerInput *input = controller->PlayerInput; if (!input) goto end; for (FInputActionKeyMapping mapping : input->GetKeysForAction(key)) { if (controller->WasInputKeyJustPressed(mapping.Key)) { Py_INCREF(Py_True); return Py_True; } } end: Py_INCREF(Py_False); return Py_False; }
PyObject *py_ue_enable_input(ue_PyUObject *self, PyObject * args) { ue_py_check(self); int controller_id = 0; if (!PyArg_ParseTuple(args, "|i:enable_input", &controller_id)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id); if (!controller) return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id); if (self->ue_object->IsA<AActor>()) { ((AActor *)self->ue_object)->EnableInput(controller); } else if (self->ue_object->IsA<UActorComponent>()) { ((UActorComponent *)self->ue_object)->GetOwner()->EnableInput(controller); } else { return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component"); } Py_INCREF(Py_None); return Py_None; }
PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args, PyObject *kwargs) { ue_py_check(self); PyObject *py_class; PyObject *py_obj_location = nullptr; PyObject *py_obj_rotation = nullptr; if (!PyArg_ParseTuple(args, "O|OO:actor_spawn", &py_class, &py_obj_location, &py_obj_rotation)) { return nullptr; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); UClass *u_class = ue_py_check_type<UClass>(py_class); if (!u_class) return PyErr_Format(PyExc_Exception, "argument is not a UClass"); if (!u_class->IsChildOf<AActor>()) { return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from AActor"); } FVector location = FVector(0, 0, 0); FRotator rotation = FRotator(0, 0, 0); if (py_obj_location) { ue_PyFVector *py_location = py_ue_is_fvector(py_obj_location); if (!py_location) return PyErr_Format(PyExc_Exception, "location must be an FVector"); location = py_location->vec; } if (py_obj_rotation) { ue_PyFRotator *py_rotation = py_ue_is_frotator(py_obj_rotation); if (!py_rotation) return PyErr_Format(PyExc_Exception, "location must be an FRotator"); rotation = py_rotation->rot; } if (kwargs && PyDict_Size(kwargs) > 0) { FTransform transform; transform.SetTranslation(location); transform.SetRotation(rotation.Quaternion()); AActor *actor = world->SpawnActorDeferred<AActor>(u_class, transform); if (!actor) return PyErr_Format(PyExc_Exception, "unable to spawn a new Actor"); ue_PyUObject *py_actor = ue_get_python_uobject_inc(actor); if (!py_actor) return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); PyObject *py_iter = PyObject_GetIter(kwargs); while (PyObject *py_key = PyIter_Next(py_iter)) { PyObject *void_ret = py_ue_set_property(py_actor, Py_BuildValue("OO", py_key, PyDict_GetItem(kwargs, py_key))); if (!void_ret) { Py_DECREF(py_iter); return PyErr_Format(PyExc_Exception, "unable to set property for new Actor"); } } Py_DECREF(py_iter); UGameplayStatics::FinishSpawningActor(actor, transform); return (PyObject *)py_actor; } AActor *actor = world->SpawnActor(u_class, &location, &rotation); if (!actor) return PyErr_Format(PyExc_Exception, "unable to spawn a new Actor"); Py_RETURN_UOBJECT(actor); }
PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args) { ue_py_check(self); PyObject *py_obj_location = nullptr; PyObject *py_obj_rotation = nullptr; UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); PyObject *obj; if (!PyArg_ParseTuple(args, "O|OO:actor_spawn", &obj, &py_obj_location, &py_obj_rotation)) { return NULL; } if (!ue_is_pyuobject(obj)) { return PyErr_Format(PyExc_Exception, "argument is not a UObject"); } ue_PyUObject *py_obj = (ue_PyUObject *)obj; if (!py_obj->ue_object->IsA<UClass>()) { return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from AActor"); } UClass *u_class = (UClass *)py_obj->ue_object; if (!u_class->IsChildOf<AActor>()) { return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from AActor"); } FVector location = FVector(0, 0, 0); FRotator rotation = FRotator(0, 0, 0); if (py_obj_location) { ue_PyFVector *py_location = py_ue_is_fvector(py_obj_location); if (!py_location) return PyErr_Format(PyExc_Exception, "location must be an FVector"); location = py_location->vec; } if (py_obj_rotation) { ue_PyFRotator *py_rotation = py_ue_is_frotator(py_obj_rotation); if (!py_rotation) return PyErr_Format(PyExc_Exception, "location must be an FRotator"); rotation = py_rotation->rot; } AActor *actor = world->SpawnActor((UClass *)py_obj->ue_object, &location, &rotation); PyObject *ret = (PyObject *)ue_get_python_wrapper(actor); if (!ret) return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); Py_INCREF(ret); return ret; }