# Missing Components Created Through C++ Constructor

**URL:** <https://forums.unrealengine.com/t/missing-components-created-through-c-constructor/247462>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [August 26, 2021, 1:53pm UTC](https://forums.unrealengine.com/t/missing-components-created-through-c-constructor/247462 "2021-08-26T13:53:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tailedmouse](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tailedmouse](https://forums.unrealengine.com/u/tailedmouse)\
**Post date:** [August 26, 2021, 1:53pm UTC](https://forums.unrealengine.com/t/missing-components-created-through-c-constructor/247462/1 "2021-08-26T13:53:42Z")

</div>

Hi,

I am running into a really frustrating problem where components created/added through C++ constructor don’t get initialized correctly if I spawn the BP version of the class in runtime.

However, if I were to place the BP directly into the world in editor, all components initialize and function properly before and during runtime.

From what I have deduced, it seems like the components may be getting initialized out of order causing them to function incorrectly.

I need these components to be preset with some configs when a BP is created of this class, so I can’t simply just make a variable and then add the components in BP.

Any help would be appreciated!

Here is sample code:

````auto
//Constructor Function
APickUpObject::APickUpObject()
{
	PrimaryActorTick.bCanEverTick = true;
	Grabbable = CreateDefaultSubobject<UGrabbingComponent>(TEXT("Grabbable"));
	Grabbable->SetupAttachment(GetRootComponent());
	Grabbable->RegisterComponent();
	Grabbable->CanCharacterStepUpOn = ECanBeCharacterBase::ECB_No;
	Grabbable->SetCollisionProfileName(TEXT("Grabbable"));
	Grabbable->SetGenerateOverlapEvents(true);
}```
````

---

<div class="post-metadata">

**Author:** ![tailedmouse](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tailedmouse](https://forums.unrealengine.com/u/tailedmouse)\
**Post date:** [August 26, 2021, 6:21pm UTC](https://forums.unrealengine.com/t/missing-components-created-through-c-constructor/247462/2 "2021-08-26T18:21:19Z")

</div>

> [@tailedmouse](#):
>
> ```auto
> Grabbable->RegisterComponent();
> 
> ```

I just resolved this incase someone needs it in future.

I believe since I am using “SetupAttachment(Object)” I don’t need “RegisterComponent()” call. Removing RegisterComponent() call fixed the issue. Here is the corrected code:

```auto

//Constructor Function
APickUpObject::APickUpObject()
{
	PrimaryActorTick.bCanEverTick = true;
	Grabbable = CreateDefaultSubobject<UGrabbingComponent>(TEXT("Grabbable"));
	Grabbable->SetupAttachment(GetRootComponent());
	Grabbable->CanCharacterStepUpOn = ECanBeCharacterBase::ECB_No;
	Grabbable->SetCollisionProfileName(TEXT("Grabbable"));
	Grabbable->SetGenerateOverlapEvents(true);
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c91def4e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c91def4e](https://forums.unrealengine.com/u/anonymous_user_c91def4e)\
**Post date:** [August 26, 2021, 10:02pm UTC](https://forums.unrealengine.com/t/missing-components-created-through-c-constructor/247462/3 "2021-08-26T22:02:25Z")

</div>

> [@tailedmouse](#):
>
> the BP version of the class in runtime.

Registering the component, or an actor for that matter menas registering it with the active WORLD.

Get real familiar with this chart. [Actor Lifecycle | Unreal Engine Documentation](https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Actors/ActorLifecycle/)

---

<div class="post-metadata">

**Author:** ![SolidGasStudios](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/solidgasstudios/32/1194575_2.png) [@SolidGasStudios](https://forums.unrealengine.com/u/SolidGasStudios)\
**Post date:** [August 27, 2021, 9:20am UTC](https://forums.unrealengine.com/t/missing-components-created-through-c-constructor/247462/4 "2021-08-27T09:20:37Z")

</div>

Don’t forget Super()  
APickUpObject::APickUpObject() : Super() { }

---

<div class="post-metadata">

**Author:** ![tailedmouse](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tailedmouse](https://forums.unrealengine.com/u/tailedmouse)\
**Post date:** [August 28, 2021, 5:47pm UTC](https://forums.unrealengine.com/t/missing-components-created-through-c-constructor/247462/5 "2021-08-28T17:47:47Z")

</div>

This was incredibly helpful! Thank you so much 🙂

---

<div class="post-metadata">

**Author:** ![tailedmouse](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tailedmouse](https://forums.unrealengine.com/u/tailedmouse)\
**Post date:** [August 28, 2021, 5:48pm UTC](https://forums.unrealengine.com/t/missing-components-created-through-c-constructor/247462/6 "2021-08-28T17:48:19Z")

</div>

Ah! Thanks for pointing that out

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [February 1, 2023, 1:40pm UTC](https://forums.unrealengine.com/t/missing-components-created-through-c-constructor/247462/7 "2023-02-01T13:40:00Z")

</div>

Constructor of the parent is automatically called if it has no parameters
