Skip to content

Commit 3e6c6e6

Browse files
author
Roberto De Ioris
committed
added pawn and controller optimized classes
1 parent c2e9033 commit 3e6c6e6

File tree

6 files changed

+101
-4
lines changed

6 files changed

+101
-4
lines changed

Source/UnrealEnginePython/Private/UEPyActor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "UnrealEnginePythonPrivatePCH.h"
22

33

4+
45
PyObject *py_ue_actor_has_tag(ue_PyUObject * self, PyObject * args) {
56

67
ue_py_check(self);
@@ -536,8 +537,8 @@ PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args) {
536537
return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from AActor");
537538
}
538539

539-
FVector location = FVector(0,0,0);
540-
FRotator rotation = FRotator(0,0,0);
540+
FVector location = FVector(0, 0, 0);
541+
FRotator rotation = FRotator(0, 0, 0);
541542

542543
if (py_obj_location) {
543544
ue_PyFVector *py_location = py_ue_is_fvector(py_obj_location);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "UnrealEnginePythonPrivatePCH.h"
2+
3+
4+
PyObject *py_ue_controller_posses(ue_PyUObject * self, PyObject * args) {
5+
6+
ue_py_check(self);
7+
8+
PyObject *obj;
9+
if (!PyArg_ParseTuple(args, "O:posses", &obj)) {
10+
return NULL;
11+
}
12+
13+
if (!self->ue_object->IsA<AController>()) {
14+
return PyErr_Format(PyExc_Exception, "uobject is not an APawn");
15+
}
16+
17+
if (!ue_is_pyuobject(obj)) {
18+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
19+
}
20+
21+
ue_PyUObject *py_obj = (ue_PyUObject *)obj;
22+
23+
if (!py_obj->ue_object->IsA<APawn>()) {
24+
return PyErr_Format(PyExc_Exception, "argument is not a APAwn");
25+
}
26+
27+
APawn *pawn = (APawn *)py_obj->ue_object;
28+
AController *controller = (AController *)self->ue_object;
29+
30+
controller->Possess(pawn);
31+
32+
Py_INCREF(Py_None);
33+
return Py_None;
34+
}
35+
36+
PyObject *py_ue_controller_unposses(ue_PyUObject * self, PyObject * args) {
37+
38+
ue_py_check(self);
39+
40+
if (!self->ue_object->IsA<AController>()) {
41+
return PyErr_Format(PyExc_Exception, "uobject is not an APawn");
42+
}
43+
44+
AController *controller = (AController *)self->ue_object;
45+
46+
controller->UnPossess();
47+
48+
Py_INCREF(Py_None);
49+
return Py_None;
50+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
4+
5+
#include "UnrealEnginePython.h"
6+
7+
PyObject *py_ue_controller_posses(ue_PyUObject *, PyObject *);
8+
PyObject *py_ue_controller_unposses(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "UEPyAssetUserData.h"
2626
#include "UEPyTexture.h"
2727
#include "UEPyMaterial.h"
28+
#include "UEPyPawn.h"
29+
#include "UEPyController.h"
2830
#if WITH_EDITOR
2931
#include "UEPyEditor.h"
3032
#include "UEPyEdGraph.h"
@@ -510,6 +512,13 @@ static PyMethodDef ue_PyUObject_methods[] = {
510512

511513
{ "get_overlapping_actors", (PyCFunction)py_ue_get_overlapping_actors, METH_VARARGS, "" },
512514

515+
// Pawn
516+
{ "get_controller", (PyCFunction)py_ue_pawn_get_controller, METH_VARARGS, "" },
517+
518+
// Controller
519+
{ "posses", (PyCFunction)py_ue_controller_posses, METH_VARARGS, "" },
520+
{ "unposses", (PyCFunction)py_ue_controller_unposses, METH_VARARGS, "" },
521+
513522

514523
// Attaching
515524

@@ -587,8 +596,8 @@ void ue_pydelegates_cleanup(ue_PyUObject *self) {
587596
UE_LOG(LogPython, Warning, TEXT("Removing UPythonDelegate %p from ue_PyUObject %p mapped to UObject %p"), py_delegate, self, self->ue_object);
588597
#endif
589598
py_delegate->RemoveFromRoot();
599+
}
590600
}
591-
}
592601
self->python_delegates_gc->clear();
593602
delete self->python_delegates_gc;
594603
self->python_delegates_gc = nullptr;
@@ -1263,7 +1272,7 @@ void unreal_engine_py_log_error() {
12631272
}
12641273

12651274
PyErr_Clear();
1266-
}
1275+
}
12671276

12681277
// retrieve a UWorld from a generic UObject (if possible)
12691278
UWorld *ue_get_uworld(ue_PyUObject *py_obj) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "UnrealEnginePythonPrivatePCH.h"
2+
3+
4+
PyObject *py_ue_pawn_get_controller(ue_PyUObject * self, PyObject * args) {
5+
6+
ue_py_check(self);
7+
8+
if (!self->ue_object->IsA<APAwn>()) {
9+
return PyErr_Format(PyExc_Exception, "uobject is not an APawn");
10+
}
11+
12+
APawn *pawn = (APAwn *)self->ue_object;
13+
14+
ue_PyUObject *ret = ue_get_python_wrapper(pawn->GetController());
15+
if (!ret)
16+
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
17+
Py_INCREF(ret);
18+
return (PyObject *)ret;
19+
}
20+
21+
22+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
4+
5+
#include "UnrealEnginePython.h"
6+
7+
PyObject *py_ue_pawn_get_controller(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)