22
33#include " Kismet/KismetSystemLibrary.h"
44
5- #include " UEPySpline.h"
6- #include " UEPyNavigation.h"
5+ #include " UEPyTransform.h"
76#include " UEPyInput.h"
7+ #include " UEPyNavigation.h"
8+ #include " UEPySpline.h"
9+
810
911
1012DEFINE_LOG_CATEGORY (LogPython);
@@ -429,125 +431,6 @@ static PyObject *py_ue_get_actor_label(ue_PyUObject *self, PyObject * args) {
429431}
430432#endif
431433
432- static PyObject *py_ue_get_actor_location (ue_PyUObject *self, PyObject * args) {
433-
434- ue_py_check (self);
435-
436- FVector vec3;
437-
438- if (self->ue_object ->IsA <AActor>()) {
439- vec3 = ((AActor *)self->ue_object )->GetActorLocation ();
440- goto ret;
441- }
442-
443- if (self->ue_object ->IsA <UActorComponent>()) {
444- vec3 = ((UActorComponent *)self->ue_object )->GetOwner ()->GetActorLocation ();
445- goto ret;
446- }
447-
448-
449- return PyErr_Format (PyExc_Exception, " uobject is not an actor or a component" );
450-
451- ret:
452- return Py_BuildValue (" fff" , vec3.X , vec3.Y , vec3.Z );
453-
454- }
455-
456- static PyObject *py_ue_get_actor_forward (ue_PyUObject *self, PyObject * args) {
457-
458- ue_py_check (self);
459-
460- FVector vec3;
461-
462- if (self->ue_object ->IsA <AActor>()) {
463- vec3 = ((AActor *)self->ue_object )->GetActorForwardVector ();
464- goto ret;
465- }
466-
467- if (self->ue_object ->IsA <UActorComponent>()) {
468- vec3 = ((UActorComponent *)self->ue_object )->GetOwner ()->GetActorForwardVector ();
469- goto ret;
470- }
471-
472-
473- return PyErr_Format (PyExc_Exception, " uobject is not an actor or a component" );
474-
475- ret:
476- return Py_BuildValue (" fff" , vec3.X , vec3.Y , vec3.Z );
477-
478- }
479-
480- static PyObject *py_ue_get_actor_right (ue_PyUObject *self, PyObject * args) {
481-
482- ue_py_check (self);
483-
484- FVector vec3;
485-
486- if (self->ue_object ->IsA <AActor>()) {
487- vec3 = ((AActor *)self->ue_object )->GetActorRightVector ();
488- goto ret;
489- }
490-
491- if (self->ue_object ->IsA <UActorComponent>()) {
492- vec3 = ((UActorComponent *)self->ue_object )->GetOwner ()->GetActorRightVector ();
493- goto ret;
494- }
495-
496-
497- return PyErr_Format (PyExc_Exception, " uobject is not an actor or a component" );
498-
499- ret:
500- return Py_BuildValue (" fff" , vec3.X , vec3.Y , vec3.Z );
501-
502- }
503-
504- static PyObject *py_ue_get_actor_up (ue_PyUObject *self, PyObject * args) {
505-
506- ue_py_check (self);
507-
508- FVector vec3;
509-
510- if (self->ue_object ->IsA <AActor>()) {
511- vec3 = ((AActor *)self->ue_object )->GetActorUpVector ();
512- goto ret;
513- }
514-
515- if (self->ue_object ->IsA <UActorComponent>()) {
516- vec3 = ((UActorComponent *)self->ue_object )->GetOwner ()->GetActorUpVector ();
517- goto ret;
518- }
519-
520-
521- return PyErr_Format (PyExc_Exception, " uobject is not an actor or a component" );
522-
523- ret:
524- return Py_BuildValue (" fff" , vec3.X , vec3.Y , vec3.Z );
525-
526- }
527-
528- static PyObject *py_ue_get_actor_rotation (ue_PyUObject *self, PyObject * args) {
529-
530- ue_py_check (self);
531-
532- FRotator vec3;
533-
534- if (self->ue_object ->IsA <AActor>()) {
535- vec3 = ((AActor *)self->ue_object )->GetActorRotation ();
536- goto ret;
537- }
538-
539- if (self->ue_object ->IsA <UActorComponent>()) {
540- vec3 = ((UActorComponent *)self->ue_object )->GetOwner ()->GetActorRotation ();
541- goto ret;
542- }
543-
544-
545- return PyErr_Format (PyExc_Exception, " uobject is not an actor or a component" );
546-
547- ret:
548- return Py_BuildValue (" fff" , vec3.Pitch , vec3.Yaw , vec3.Roll );
549-
550- }
551434
552435static PyObject *py_ue_get_actor_velocity (ue_PyUObject *self, PyObject * args) {
553436
@@ -591,6 +474,7 @@ static PyObject *py_ue_quit_game(ue_PyUObject *self, PyObject * args) {
591474
592475
593476
477+
594478static PyObject *py_ue_get_world (ue_PyUObject *self, PyObject * args) {
595479
596480 ue_py_check (self);
@@ -611,89 +495,6 @@ static PyObject *py_ue_get_world(ue_PyUObject *self, PyObject * args) {
611495
612496
613497
614- static PyObject *py_ue_set_actor_location (ue_PyUObject *self, PyObject * args) {
615-
616- ue_py_check (self);
617-
618- float x, y, z;
619- if (!PyArg_ParseTuple (args, " fff:set_actor_location" , &x, &y, &z)) {
620- return NULL ;
621- }
622-
623- if (self->ue_object ->IsA <AActor>()) {
624- ((AActor *)self->ue_object )->SetActorLocation (FVector (x, y, z));
625- goto ret;
626- }
627-
628- if (self->ue_object ->IsA <UActorComponent>()) {
629- ((UActorComponent *)self->ue_object )->GetOwner ()->SetActorLocation (FVector (x, y, z));
630- goto ret;
631- }
632-
633- return PyErr_Format (PyExc_Exception, " uobject is not an actor or a component" );
634-
635- ret:
636- Py_INCREF (Py_None);
637- return Py_None;
638-
639- }
640-
641- static PyObject *py_ue_set_actor_rotation (ue_PyUObject *self, PyObject * args) {
642-
643- ue_py_check (self);
644-
645- float pitch, yaw, roll;
646- if (!PyArg_ParseTuple (args, " fff:set_actor_rotation" , &pitch, &yaw, &roll)) {
647- return NULL ;
648- }
649-
650- if (self->ue_object ->IsA <AActor>()) {
651- ((AActor *)self->ue_object )->SetActorRotation (FRotator (pitch, yaw, roll));
652- goto ret;
653- }
654-
655- if (self->ue_object ->IsA <UActorComponent>()) {
656- ((UActorComponent *)self->ue_object )->GetOwner ()->SetActorRotation (FRotator (pitch, yaw, roll));
657- goto ret;
658- }
659-
660- return PyErr_Format (PyExc_Exception, " uobject is not an actor or a component" );
661-
662- ret:
663- Py_INCREF (Py_None);
664- return Py_None;
665-
666- }
667-
668- static PyObject *py_ue_find_object (ue_PyUObject * self, PyObject * args) {
669-
670- ue_py_check (self);
671-
672- char *name;
673- if (!PyArg_ParseTuple (args, " s:find_object" , &name)) {
674- return NULL ;
675- }
676- UObject *u_object = nullptr ;
677-
678- for (TObjectIterator<UObject> Itr; Itr; ++Itr) {
679- UObject *u_obj = *Itr;
680- if (u_obj->GetName ().Equals (UTF8_TO_TCHAR (name))) {
681- u_object = u_obj;
682- break ;
683- }
684- }
685-
686- if (u_object) {
687- ue_PyUObject *ret = ue_get_python_wrapper (u_object);
688- if (!ret)
689- return PyErr_Format (PyExc_Exception, " PyUObject is in invalid state" );
690- Py_INCREF (ret);
691- return (PyObject *)ret;
692- }
693-
694- Py_INCREF (Py_None);
695- return Py_None;
696- }
697498
698499static PyObject *py_ue_find_function (ue_PyUObject * self, PyObject * args) {
699500
@@ -1107,19 +908,49 @@ static PyObject *py_ue_set_view_target(ue_PyUObject *, PyObject *);
1107908static PyObject *py_ue_add_actor_component (ue_PyUObject *, PyObject *);
1108909static PyObject *py_ue_get_actor_component_by_type (ue_PyUObject *, PyObject *);
1109910static PyObject *py_ue_add_actor_root_component (ue_PyUObject *, PyObject *);
911+ static PyObject *py_ue_play_sound_at_location (ue_PyUObject *, PyObject *);
1110912
1111913static PyMethodDef ue_PyUObject_methods[] = {
914+
915+ // Transform
916+
1112917 { " get_actor_location" , (PyCFunction)py_ue_get_actor_location, METH_VARARGS, " " },
918+ { " get_actor_rotation" , (PyCFunction)py_ue_get_actor_rotation, METH_VARARGS, " " },
919+
1113920 { " get_actor_forward" , (PyCFunction)py_ue_get_actor_forward, METH_VARARGS, " " },
1114921 { " get_actor_right" , (PyCFunction)py_ue_get_actor_right, METH_VARARGS, " " },
1115922 { " get_actor_up" , (PyCFunction)py_ue_get_actor_up, METH_VARARGS, " " },
1116- { " get_actor_rotation " , (PyCFunction)py_ue_get_actor_rotation, METH_VARARGS, " " },
1117- { " get_actor_velocity " , (PyCFunction)py_ue_get_actor_velocity, METH_VARARGS, " " },
1118- { " set_actor_location " , (PyCFunction)py_ue_set_actor_location, METH_VARARGS, " " },
923+
924+
925+
1119926 { " set_actor_rotation" , (PyCFunction)py_ue_set_actor_rotation, METH_VARARGS, " " },
927+ { " set_actor_location" , (PyCFunction)py_ue_set_actor_location, METH_VARARGS, " " },
928+
929+
930+ { " get_world_location" , (PyCFunction)py_ue_get_world_location, METH_VARARGS, " " },
931+ { " get_world_rotation" , (PyCFunction)py_ue_get_world_rotation, METH_VARARGS, " " },
932+ { " get_world_scale" , (PyCFunction)py_ue_get_world_scale, METH_VARARGS, " " },
933+ { " get_relative_location" , (PyCFunction)py_ue_get_relative_location, METH_VARARGS, " " },
934+ { " get_relative_rotation" , (PyCFunction)py_ue_get_relative_rotation, METH_VARARGS, " " },
935+ { " get_relative_scale" , (PyCFunction)py_ue_get_relative_scale, METH_VARARGS, " " },
936+
937+ { " set_world_location" , (PyCFunction)py_ue_set_world_location, METH_VARARGS, " " },
938+ { " set_world_rotation" , (PyCFunction)py_ue_set_world_rotation, METH_VARARGS, " " },
939+ { " set_world_scale" , (PyCFunction)py_ue_set_world_scale, METH_VARARGS, " " },
940+ { " set_relative_location" , (PyCFunction)py_ue_set_relative_location, METH_VARARGS, " " },
941+ { " set_relative_rotation" , (PyCFunction)py_ue_set_relative_rotation, METH_VARARGS, " " },
942+ { " set_relative_scale" , (PyCFunction)py_ue_set_relative_scale, METH_VARARGS, " " },
943+
944+ { " get_forward_vector" , (PyCFunction)py_ue_get_forward_vector, METH_VARARGS, " " },
945+ { " get_up_vector" , (PyCFunction)py_ue_get_up_vector, METH_VARARGS, " " },
946+ { " get_right_vector" , (PyCFunction)py_ue_get_right_vector, METH_VARARGS, " " },
947+
948+ // UObject
949+
1120950 { " get_property" , (PyCFunction)py_ue_get_property, METH_VARARGS, " " },
1121951 { " set_property" , (PyCFunction)py_ue_set_property, METH_VARARGS, " " },
1122952 { " properties" , (PyCFunction)py_ue_properties, METH_VARARGS, " " },
953+
1123954 { " call" , (PyCFunction)py_ue_call, METH_VARARGS, " " },
1124955 { " get_owner" , (PyCFunction)py_ue_get_owner, METH_VARARGS, " " },
1125956 { " get_name" , (PyCFunction)py_ue_get_name, METH_VARARGS, " " },
@@ -1128,14 +959,25 @@ static PyMethodDef ue_PyUObject_methods[] = {
1128959 { " get_actor_label" , (PyCFunction)py_ue_get_actor_label, METH_VARARGS, " " },
1129960 { " find_actor_by_label" , (PyCFunction)py_ue_find_actor_by_label, METH_VARARGS, " " },
1130961#endif
1131- { " find_object" , (PyCFunction)py_ue_find_object, METH_VARARGS, " " },
962+
963+
1132964 { " find_function" , (PyCFunction)py_ue_find_function, METH_VARARGS, " " },
1133965 { " call_function" , (PyCFunction)py_ue_call_function, METH_VARARGS, " " },
966+
967+
1134968 { " all_objects" , (PyCFunction)py_ue_all_objects, METH_VARARGS, " " },
1135969 { " all_actors" , (PyCFunction)py_ue_all_actors, METH_VARARGS, " " },
970+
971+ // Input
972+
1136973 { " get_input_axis" , (PyCFunction)py_ue_get_input_axis, METH_VARARGS, " " },
1137974 { " bind_input_axis" , (PyCFunction)py_ue_bind_input_axis, METH_VARARGS, " " },
1138975 { " enable_input" , (PyCFunction)py_ue_enable_input, METH_VARARGS, " " },
976+ { " show_mouse_cursor" , (PyCFunction)py_ue_show_mouse_cursor, METH_VARARGS, " " },
977+ { " enable_click_events" , (PyCFunction)py_ue_enable_click_events, METH_VARARGS, " " },
978+ { " enable_mouse_over_events" , (PyCFunction)py_ue_enable_mouse_over_events, METH_VARARGS, " " },
979+
980+
1139981 { " get_class" , (PyCFunction)py_ue_get_class, METH_VARARGS, " " },
1140982 { " actor_components" , (PyCFunction)py_ue_actor_components, METH_VARARGS, " " },
1141983 { " quit_game" , (PyCFunction)py_ue_quit_game, METH_VARARGS, " " },
@@ -1146,22 +988,30 @@ static PyMethodDef ue_PyUObject_methods[] = {
1146988 { " actor_spawn" , (PyCFunction)py_ue_actor_spawn, METH_VARARGS, " " },
1147989 { " actor_has_tag" , (PyCFunction)py_ue_actor_has_tag, METH_VARARGS, " " },
1148990 { " get_actor_bounds" , (PyCFunction)py_ue_get_actor_bounds, METH_VARARGS, " " },
991+
1149992 { " line_trace_single_by_channel" , (PyCFunction)py_ue_line_trace_single_by_channel, METH_VARARGS, " " },
1150993 { " line_trace_multi_by_channel" , (PyCFunction)py_ue_line_trace_multi_by_channel, METH_VARARGS, " " },
1151994 { " get_hit_result_under_cursor" , (PyCFunction)py_ue_get_hit_result_under_cursor, METH_VARARGS, " " },
1152- { " show_mouse_cursor" , (PyCFunction)py_ue_show_mouse_cursor, METH_VARARGS, " " },
1153- { " enable_click_events" , (PyCFunction)py_ue_enable_click_events, METH_VARARGS, " " },
1154- { " enable_mouse_over_events" , (PyCFunction)py_ue_enable_mouse_over_events, METH_VARARGS, " " },
995+
1155996 { " destructible_apply_damage" , (PyCFunction)py_ue_destructible_apply_damage, METH_VARARGS, " " },
997+
1156998 { " set_view_target" , (PyCFunction)py_ue_set_view_target, METH_VARARGS, " " },
999+
11571000 { " add_actor_component" , (PyCFunction)py_ue_add_actor_component, METH_VARARGS, " " },
11581001 { " add_actor_root_component" , (PyCFunction)py_ue_add_actor_root_component, METH_VARARGS, " " },
11591002 { " get_actor_component_by_type" , (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, " " },
11601003 { " get_component_by_type" , (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, " " },
1004+
11611005 { " set_simulate_physics" , (PyCFunction)py_ue_set_simulate_physics, METH_VARARGS, " " },
11621006 { " get_world" , (PyCFunction)py_ue_get_world, METH_VARARGS, " " },
1007+
11631008 { " get_world_location_at_distance_along_spline" , (PyCFunction)py_ue_get_world_location_at_distance_along_spline, METH_VARARGS, " " },
11641009 { " get_spline_length" , (PyCFunction)py_ue_get_spline_length, METH_VARARGS, " " },
1010+
1011+ { " get_actor_velocity" , (PyCFunction)py_ue_get_actor_velocity, METH_VARARGS, " " },
1012+
1013+ { " play_sound_at_location" , (PyCFunction)py_ue_play_sound_at_location, METH_VARARGS, " " },
1014+
11651015 { NULL } /* Sentinel */
11661016};
11671017
@@ -1236,6 +1086,46 @@ static PyObject *py_ue_add_actor_component(ue_PyUObject * self, PyObject * args)
12361086
12371087}
12381088
1089+ static PyObject *py_ue_play_sound_at_location (ue_PyUObject *self, PyObject * args) {
1090+
1091+ ue_py_check (self);
1092+
1093+ UWorld *world = ue_get_uworld (self);
1094+ if (!world)
1095+ return PyErr_Format (PyExc_Exception, " unable to retrieve UWorld from uobject" );
1096+
1097+ PyObject *sound;
1098+ float x, y, z;
1099+ float volume = 1 ;
1100+ float pitch = 1 ;
1101+ float start = 0 ;
1102+
1103+ if (!PyArg_ParseTuple (args, " Offf|fff:play_sound_at_location" , &sound, &x, &y, &z, &volume, &pitch, &start)) {
1104+ return NULL ;
1105+ }
1106+
1107+
1108+ USoundBase *sound_object = nullptr ;
1109+ if (PyObject_IsInstance (sound, (PyObject *)&ue_PyUObjectType)) {
1110+ ue_PyUObject *py_sound = (ue_PyUObject *)sound;
1111+ if (py_sound->ue_object ->IsA <USoundBase>()) {
1112+ sound_object = (USoundBase *)py_sound->ue_object ;
1113+ }
1114+ }
1115+ else if (PyUnicode_Check (sound)) {
1116+ sound_object = FindObject<USoundBase>(ANY_PACKAGE, UTF8_TO_TCHAR (PyUnicode_AsUTF8 (sound)));
1117+ }
1118+
1119+ if (!sound_object)
1120+ return PyErr_Format (PyExc_Exception, " invalid sound object" );
1121+
1122+ UGameplayStatics::PlaySoundAtLocation (self->ue_object , sound_object, FVector (x, y, z), volume, pitch, start);
1123+
1124+ Py_INCREF (Py_None);
1125+ return Py_None;
1126+ }
1127+
1128+
12391129static PyObject *py_ue_add_actor_root_component (ue_PyUObject * self, PyObject * args) {
12401130
12411131 ue_py_check (self);
0 commit comments