# Create & attach component to parent Actor from child Component?

**URL:** <https://forums.unrealengine.com/t/create-attach-component-to-parent-actor-from-child-component/237522>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [June 26, 2021, 4:32am UTC](https://forums.unrealengine.com/t/create-attach-component-to-parent-actor-from-child-component/237522 "2021-06-26T04:32:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RemzDNB](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/remzdnb/32/88719_2.png) [@RemzDNB](https://forums.unrealengine.com/u/RemzDNB)\
**Post date:** [June 26, 2021, 4:32am UTC](https://forums.unrealengine.com/t/create-attach-component-to-parent-actor-from-child-component/237522/1 "2021-06-26T04:32:47Z")

</div>

Hello !  
I’m trying to make a CameraManager component, which would automatically create and attach a SpringArm and a Camera to its parent Actor.  
I got some answers from here [thread](https://forums.unrealengine.com/t/what-is-the-correct-way-to-create-and-add-components-at-runtime/15605/7) but no luck so far.

I tried

USpringArmComponent\* SpringArmCT = NewObject(GetOwner(), USpringArmComponent::StaticClass(), “SpringArmCT”);  
if (SpringArmCT)  
{  
SpringArmCT-\>RegisterComponent();  
SpringArmCT-\>AttachTo(GetOwner()-\>GetRootComponent());  
}

but it doesn’t work, the component doesn’t show up at runtime.

I tried SpringArmCT-\>OnComponentCreated(), SpringArmCT-\>InitializeComponent(), but it still doesn’t work ☹

Any help pls ? thanks 🙂

Edit : I also tried

USpringArmComponent\* SpringArmCT = NewObject(GetOwner(), TEXT(“SpringArmCT”));  
if (SpringArmCT)  
{  
SpringArmCT-\>SetupAttachment(GetOwner()-\>GetRootComponent());  
SpringArmCT-\>RegisterComponent();  
}

and some other variants lol … nothing works. And btw I call this from the component BeginPlay.

☹

---

<div class="post-metadata">

**Author:** ![RemzDNB](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/remzdnb/32/88719_2.png) [@RemzDNB](https://forums.unrealengine.com/u/RemzDNB)\
**Post date:** [June 26, 2021, 2:29pm UTC](https://forums.unrealengine.com/t/create-attach-component-to-parent-actor-from-child-component/237522/2 "2021-06-26T14:29:54Z")

</div>

So I tried to write the same code in the parent Actor BeginPlay…

```
SpringArmCT = NewObject<USpringArmComponent>(this, TEXT("SpringArmCT"));
if (SpringArmCT)
{
	UE_LOG(LogTemp, Warning, TEXT("Comp Added ?"));
	SpringArmCT->SetupAttachment(RootComponent);
	SpringArmCT->RegisterComponent();
}

```

… and it works. I’m missing something.

Please someone help !

---

<div class="post-metadata">

**Author:** ![burtonpoo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@burtonpoo](https://forums.unrealengine.com/u/burtonpoo)\
**Post date:** [August 4, 2023, 9:47am UTC](https://forums.unrealengine.com/t/create-attach-component-to-parent-actor-from-child-component/237522/3 "2023-08-04T09:47:52Z")

</div>

change order

RegisterComponent FIrst → SetupAttachment

and Add Option

for example  
AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
