Skip to content

Commit 8ecf987

Browse files
author
Roberto De Ioris
committed
added actor scaling support
1 parent ca1967f commit 8ecf987

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -916,15 +916,16 @@ static PyMethodDef ue_PyUObject_methods[] = {
916916

917917
{ "get_actor_location", (PyCFunction)py_ue_get_actor_location, METH_VARARGS, "" },
918918
{ "get_actor_rotation", (PyCFunction)py_ue_get_actor_rotation, METH_VARARGS, "" },
919+
{ "get_actor_scale", (PyCFunction)py_ue_get_actor_scale, METH_VARARGS, "" },
919920

920921
{ "get_actor_forward", (PyCFunction)py_ue_get_actor_forward, METH_VARARGS, "" },
921922
{ "get_actor_right", (PyCFunction)py_ue_get_actor_right, METH_VARARGS, "" },
922923
{ "get_actor_up", (PyCFunction)py_ue_get_actor_up, METH_VARARGS, "" },
923924

924925

925-
926-
{ "set_actor_rotation", (PyCFunction)py_ue_set_actor_rotation, METH_VARARGS, "" },
927926
{ "set_actor_location", (PyCFunction)py_ue_set_actor_location, METH_VARARGS, "" },
927+
{ "set_actor_rotation", (PyCFunction)py_ue_set_actor_rotation, METH_VARARGS, "" },
928+
{ "set_actor_scale", (PyCFunction)py_ue_set_actor_scale, METH_VARARGS, "" },
928929

929930

930931
{ "get_world_location", (PyCFunction)py_ue_get_world_location, METH_VARARGS, "" },
@@ -1090,10 +1091,6 @@ static PyObject *py_ue_play_sound_at_location(ue_PyUObject *self, PyObject * arg
10901091

10911092
ue_py_check(self);
10921093

1093-
UWorld *world = ue_get_uworld(self);
1094-
if (!world)
1095-
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
1096-
10971094
PyObject *sound;
10981095
float x, y, z;
10991096
float volume = 1;

Source/UnrealEnginePython/Private/UEPyTransform.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ PyObject *py_ue_get_actor_location(ue_PyUObject *self, PyObject * args) {
2626

2727
}
2828

29+
PyObject *py_ue_get_actor_scale(ue_PyUObject *self, PyObject * args) {
30+
31+
ue_py_check(self);
32+
33+
FVector vec3;
34+
35+
if (self->ue_object->IsA<AActor>()) {
36+
vec3 = ((AActor *)self->ue_object)->GetActorScale3D();
37+
goto ret;
38+
}
39+
40+
if (self->ue_object->IsA<UActorComponent>()) {
41+
vec3 = ((UActorComponent *)self->ue_object)->GetOwner()->GetActorScale3D();
42+
goto ret;
43+
}
44+
45+
46+
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
47+
48+
ret:
49+
return Py_BuildValue("fff", vec3.X, vec3.Y, vec3.Z);
50+
51+
}
52+
2953
PyObject *py_ue_get_actor_forward(ue_PyUObject *self, PyObject * args) {
3054

3155
ue_py_check(self);
@@ -149,6 +173,33 @@ PyObject *py_ue_set_actor_location(ue_PyUObject *self, PyObject * args) {
149173

150174
}
151175

176+
PyObject *py_ue_set_actor_scale(ue_PyUObject *self, PyObject * args) {
177+
178+
ue_py_check(self);
179+
180+
float x, y, z;
181+
if (!PyArg_ParseTuple(args, "fff:set_actor_scale", &x, &y, &z)) {
182+
return NULL;
183+
}
184+
185+
if (self->ue_object->IsA<AActor>()) {
186+
((AActor *)self->ue_object)->SetActorScale3D(FVector(x, y, z));
187+
goto ret;
188+
}
189+
190+
if (self->ue_object->IsA<UActorComponent>()) {
191+
((UActorComponent *)self->ue_object)->GetOwner()->SetActorScale3D(FVector(x, y, z));
192+
goto ret;
193+
}
194+
195+
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
196+
197+
ret:
198+
Py_INCREF(Py_None);
199+
return Py_None;
200+
201+
}
202+
152203
PyObject *py_ue_set_actor_rotation(ue_PyUObject *self, PyObject * args) {
153204

154205
ue_py_check(self);

Source/UnrealEnginePython/Private/UEPyTransform.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
#include "UnrealEnginePython.h"
66

7-
PyObject *py_ue_get_actor_location(ue_PyUObject *, PyObject *);
8-
97
PyObject *py_ue_get_actor_location(ue_PyUObject *, PyObject *);
108
PyObject *py_ue_get_actor_rotation(ue_PyUObject *, PyObject *);
9+
PyObject *py_ue_get_actor_scale(ue_PyUObject *, PyObject *);
1110

1211
PyObject *py_ue_get_actor_forward(ue_PyUObject *, PyObject *);
1312
PyObject *py_ue_get_actor_right(ue_PyUObject *, PyObject *);
@@ -17,6 +16,7 @@ PyObject *py_ue_get_actor_up(ue_PyUObject *, PyObject *);
1716

1817
PyObject *py_ue_set_actor_rotation(ue_PyUObject *, PyObject *);
1918
PyObject *py_ue_set_actor_location(ue_PyUObject *, PyObject *);
19+
PyObject *py_ue_set_actor_scale(ue_PyUObject *, PyObject *);
2020

2121

2222
PyObject *py_ue_get_world_location(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)