Skip to content

Commit 6b508d5

Browse files
author
Roberto De Ioris
committed
more robust add_actor_component()
1 parent 721aaab commit 6b508d5

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Source/UnrealEnginePython/Private/UObject/UEPyActor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ PyObject *py_ue_add_actor_component(ue_PyUObject * self, PyObject * args) {
336336
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
337337
}
338338

339+
UClass *u_class = (UClass *)py_obj->ue_object;
340+
341+
if (!u_class->IsChildOf<UActorComponent>()) {
342+
return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from AActor");
343+
}
344+
339345
USceneComponent *parent_component = nullptr;
340346

341347
if (py_parent) {
@@ -345,7 +351,7 @@ PyObject *py_ue_add_actor_component(ue_PyUObject * self, PyObject * args) {
345351
}
346352
}
347353

348-
UActorComponent *component = NewObject<UActorComponent>(actor, (UClass *)py_obj->ue_object, FName(UTF8_TO_TCHAR(name)));
354+
UActorComponent *component = NewObject<UActorComponent>(actor, u_class, FName(UTF8_TO_TCHAR(name)));
349355
if (!component)
350356
return PyErr_Format(PyExc_Exception, "unable to create component");
351357

0 commit comments

Comments
 (0)