Skip to content

Commit 230d009

Browse files
author
Roberto De Ioris
committed
added add_instance_component()
1 parent 94453cc commit 230d009

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
720720

721721

722722
{ "add_actor_component", (PyCFunction)py_ue_add_actor_component, METH_VARARGS, "" },
723+
{ "add_instance_component", (PyCFunction)py_ue_add_instance_component, METH_VARARGS, "" },
723724
{ "add_actor_root_component", (PyCFunction)py_ue_add_actor_root_component, METH_VARARGS, "" },
724725
{ "get_actor_component_by_type", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },
725726
{ "get_component_by_type", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UObject/UEPyActor.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,36 @@ PyObject *py_ue_destroy_component(ue_PyUObject * self, PyObject * args) {
343343
Py_RETURN_NONE;
344344
}
345345

346+
PyObject *py_ue_add_instance_component(ue_PyUObject * self, PyObject * args)
347+
{
348+
349+
ue_py_check(self);
350+
351+
PyObject *py_component;
352+
if (!PyArg_ParseTuple(args, "O:add_instance_component", &py_component))
353+
{
354+
return nullptr;
355+
}
356+
357+
358+
AActor *actor = ue_py_check_type<AActor>(self);
359+
if (!actor)
360+
{
361+
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
362+
}
363+
364+
UActorComponent *component = ue_py_check_type<UActorComponent>(py_component);
365+
if (!component)
366+
{
367+
return PyErr_Format(PyExc_Exception, "argument is not a UActorComponent");
368+
}
369+
370+
actor->AddInstanceComponent(component);
371+
Py_RETURN_NONE;
372+
373+
}
374+
375+
346376
PyObject *py_ue_add_actor_component(ue_PyUObject * self, PyObject * args) {
347377

348378
ue_py_check(self);

Source/UnrealEnginePython/Private/UObject/UEPyActor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ PyObject *py_ue_register_component(ue_PyUObject * self, PyObject *);
3434
PyObject *py_ue_unregister_component(ue_PyUObject * self, PyObject *);
3535
PyObject *py_ue_destroy_component(ue_PyUObject * self, PyObject *);
3636
PyObject *py_ue_component_is_registered(ue_PyUObject * self, PyObject *);
37-
PyObject *py_ue_actor_create_default_subobject(ue_PyUObject * self, PyObject *);
37+
PyObject *py_ue_actor_create_default_subobject(ue_PyUObject * self, PyObject *);
38+
PyObject *py_ue_add_instance_component(ue_PyUObject * self, PyObject *);

examples/add_instance_component.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import unreal_engine as ue
2+
from unreal_engine.classes import PawnSensingComponent
3+
from unreal_engine.enums import EComponentCreationMethod
4+
5+
actor = ue.editor_get_selected_actors()[0]
6+
component = actor.add_actor_component(PawnSensingComponent, 'Foo')
7+
actor.add_instance_component(component)
8+
actor.modify()

0 commit comments

Comments
 (0)