Skip to content

Commit aea38fa

Browse files
author
Roberto De Ioris
committed
preliminary support for destructible
1 parent 858fc4d commit aea38fa

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ static PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject * self, PyObject
10801080
static PyObject *py_ue_is_a(ue_PyUObject *, PyObject *);
10811081
static PyObject *py_ue_actor_has_component_of_type(ue_PyUObject *, PyObject *);
10821082
static PyObject *py_ue_actor_spawn(ue_PyUObject *, PyObject *);
1083+
static PyObject *py_ue_destructible_apply_damage(ue_PyUObject *, PyObject *);
10831084

10841085
static PyMethodDef ue_PyUObject_methods[] = {
10851086
{ "get_actor_location", (PyCFunction)py_ue_get_actor_location, METH_VARARGS, "" },
@@ -1120,6 +1121,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
11201121
{ "show_mouse_cursor", (PyCFunction)py_ue_show_mouse_cursor, METH_VARARGS, "" },
11211122
{ "enable_click_events", (PyCFunction)py_ue_enable_click_events, METH_VARARGS, "" },
11221123
{ "enable_mouse_over_events", (PyCFunction)py_ue_enable_mouse_over_events, METH_VARARGS, "" },
1124+
{ "destructible_apply_damage", (PyCFunction)py_ue_destructible_apply_damage, METH_VARARGS, "" },
11231125
{ NULL } /* Sentinel */
11241126
};
11251127

@@ -1245,6 +1247,46 @@ static PyObject *py_ue_is_a(ue_PyUObject * self, PyObject * args) {
12451247
return Py_False;
12461248
}
12471249

1250+
static PyObject *py_ue_destructible_apply_damage(ue_PyUObject * self, PyObject * args) {
1251+
1252+
ue_py_check(self);
1253+
1254+
float damage_amount = 0;
1255+
float impulse_strength = 0;
1256+
float x = 0, y = 0, z = 0;
1257+
float ix = 0, iy = 0, iz = 0;
1258+
if (!PyArg_ParseTuple(args, "ffffffff:destructible_apply_damage", &damage_amount, &impulse_strength, &x, &y, &z, &ix, &iy, &iz)) {
1259+
return NULL;
1260+
}
1261+
1262+
UDestructibleComponent *destructible = nullptr;
1263+
AActor *actor = nullptr;
1264+
1265+
if (self->ue_object->IsA<UDestructibleComponent>()) {
1266+
destructible = (UDestructibleComponent *)self->ue_object;
1267+
}
1268+
else if (self->ue_object->IsA<AActor>()) {
1269+
actor = (AActor *)self->ue_object;
1270+
destructible = (UDestructibleComponent *) actor->GetComponentByClass(UDestructibleComponent::StaticClass());
1271+
}
1272+
else if (self->ue_object->IsA<UActorComponent>()) {
1273+
actor = (AActor *)self->ue_object->GetOuter();
1274+
if (actor) {
1275+
destructible = (UDestructibleComponent *)actor->GetComponentByClass(UDestructibleComponent::StaticClass());
1276+
}
1277+
}
1278+
1279+
if (destructible) {
1280+
destructible->ApplyDamage(damage_amount, FVector(x, y, z), FVector(ix, iy, iz), impulse_strength);
1281+
}
1282+
else {
1283+
return PyErr_Format(PyExc_Exception, "UObject is not a destructible");
1284+
}
1285+
1286+
Py_INCREF(Py_False);
1287+
return Py_False;
1288+
}
1289+
12481290
void unreal_engine_init_py_module() {
12491291
PyImport_AppendInittab("unreal_engine", init_unreal_engine);
12501292
PyObject *new_unreal_engine_module = PyImport_AddModule("unreal_engine");

0 commit comments

Comments
 (0)