@@ -274,7 +274,8 @@ PyObject *py_ue_register_component(ue_PyUObject *self, PyObject * args) {
274274
275275 UActorComponent *component = (UActorComponent *)self->ue_object ;
276276
277- component->RegisterComponent ();
277+ if (!component->IsRegistered ())
278+ component->RegisterComponent ();
278279
279280 Py_INCREF (Py_None);
280281 return Py_None;
@@ -324,7 +325,8 @@ PyObject *py_ue_unregister_component(ue_PyUObject * self, PyObject * args) {
324325 if (!component)
325326 return PyErr_Format (PyExc_Exception, " uobject is not an UActorComponent" );
326327
327- component->UnregisterComponent ();
328+ if (component->IsRegistered ())
329+ component->UnregisterComponent ();
328330
329331 Py_RETURN_NONE;
330332}
@@ -392,11 +394,11 @@ PyObject *py_ue_add_actor_component(ue_PyUObject * self, PyObject * args) {
392394 scene_component->SetupAttachment (parent_component);
393395 }
394396
395- if (actor->GetWorld ()) {
397+ if (actor->GetWorld () && !component-> IsRegistered () ) {
396398 component->RegisterComponent ();
397399 }
398400
399- if (component->bWantsInitializeComponent && !component->HasBeenInitialized ())
401+ if (component->bWantsInitializeComponent && !component->HasBeenInitialized () && component-> IsRegistered () )
400402 component->InitializeComponent ();
401403
402404 PyObject *ret = (PyObject *)ue_get_python_wrapper (component);
@@ -429,11 +431,11 @@ PyObject *py_ue_add_python_component(ue_PyUObject * self, PyObject * args) {
429431 component->PythonModule = FString (UTF8_TO_TCHAR (module_name));
430432 component->PythonClass = FString (UTF8_TO_TCHAR (class_name));
431433
432- if (actor->GetWorld ()) {
434+ if (actor->GetWorld () && !component-> IsRegistered () ) {
433435 component->RegisterComponent ();
434436 }
435437
436- if (component->bWantsInitializeComponent && !component->HasBeenInitialized ())
438+ if (component->bWantsInitializeComponent && !component->HasBeenInitialized () && component-> IsRegistered () )
437439 component->InitializeComponent ();
438440
439441 PyObject *ret = (PyObject *)ue_get_python_wrapper (component);
@@ -453,23 +455,18 @@ PyObject *py_ue_actor_create_default_subobject(ue_PyUObject * self, PyObject * a
453455 return NULL ;
454456 }
455457
456- if (!self->ue_object ->IsA <AActor>()) {
458+ AActor *actor = ue_py_check_type<AActor>(self);
459+ if (!actor)
457460 return PyErr_Format (PyExc_Exception, " uobject is not an AActor" );
458- }
459-
460- AActor *actor = (AActor *)self->ue_object ;
461-
462- if (!ue_is_pyuobject (obj)) {
463- return PyErr_Format (PyExc_Exception, " argument is not a UObject" );
464- }
465461
466- ue_PyUObject *py_obj = (ue_PyUObject *)obj;
462+ UClass *u_class = ue_py_check_type<UClass>(obj);
463+ if (!u_class)
464+ return PyErr_Format (PyExc_Exception, " argument is not a UClass" );
467465
468- if (!py_obj->ue_object ->IsA <UClass>()) {
469- return PyErr_Format (PyExc_Exception, " argument is not a class" );
470- }
466+ if (!FUObjectThreadContext::Get ().TopInitializer ())
467+ return PyErr_Format (PyExc_Exception, " CreateDefaultSubobject() can be called only in a constructor" );
471468
472- UObject *ret_obj = actor->CreateDefaultSubobject (FName (UTF8_TO_TCHAR (name)), UObject::StaticClass (), (UClass *)py_obj-> ue_object , false , false , true );
469+ UObject *ret_obj = actor->CreateDefaultSubobject (FName (UTF8_TO_TCHAR (name)), UObject::StaticClass (), u_class , false , false , true );
473470 if (!ret_obj)
474471 return PyErr_Format (PyExc_Exception, " unable to create component" );
475472
@@ -513,11 +510,11 @@ PyObject *py_ue_add_actor_root_component(ue_PyUObject * self, PyObject * args) {
513510
514511 actor->SetRootComponent (component);
515512
516- if (actor->GetWorld ()) {
513+ if (actor->GetWorld () && !component-> IsRegistered () ) {
517514 component->RegisterComponent ();
518515 }
519516
520- if (component->bWantsInitializeComponent && !component->HasBeenInitialized ())
517+ if (component->bWantsInitializeComponent && !component->HasBeenInitialized () && component-> IsRegistered () )
521518 component->InitializeComponent ();
522519
523520 PyObject *ret = (PyObject *)ue_get_python_wrapper (component);
0 commit comments