# How to create and attach a UActorComponent at runtime

**URL:** <https://forums.unrealengine.com/t/how-to-create-and-attach-a-uactorcomponent-at-runtime/491666>\
**Category:** Community & Industry Discussion\
**Tags:** actorcomponent, unreal-engine, runtime, question\
**Created:** [December 7, 2021, 3:51am UTC](https://forums.unrealengine.com/t/how-to-create-and-attach-a-uactorcomponent-at-runtime/491666 "2021-12-07T03:51:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Floydx23](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Floydx23](https://forums.unrealengine.com/u/Floydx23)\
**Post date:** [December 7, 2021, 3:51am UTC](https://forums.unrealengine.com/t/how-to-create-and-attach-a-uactorcomponent-at-runtime/491666/1 "2021-12-07T03:51:34Z")

</div>

Hey everyone,  
I’m trying to create a UActorComponent and attach it to an AActor. I am creating the component outside of the actor I want to attach it to. The commented stuff is just some stuff I tried but also failed.

 ![353652-help.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/0/7/e0732d6fca4e7cc2847263039bb98b992bea3633.png)

(In case that pic is too small)

UPloppableComponent\* NewPloppableComp = NewObject(PlaceableActor, UPloppableComponent::StaticClass(), TEXT(“PloppableComponent”), RF\_Transient);

PlaceableActor-\>AddInstanceComponent(NewPloppableComp);

```
	//FTransform transform;
	//PlaceableActor->AddComponent(TEXT("PloppableComponent"), false, transform, UPloppableComponent::StaticClass());
	
	//UActorComponent* NewComp = NewObject<UActorComponent>(PlaceableActor, UPloppableComponent::StaticClass(), TEXT("PloppableComponent"));
	//NewComp.(PlaceableActor->GetRootComponent());

```

---

<div class="post-metadata">

**Author:** ![lucoiso](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lucoiso/32/820744_2.png) [@lucoiso](https://forums.unrealengine.com/u/lucoiso)\
**Post date:** [December 7, 2021, 12:51pm UTC](https://forums.unrealengine.com/t/how-to-create-and-attach-a-uactorcomponent-at-runtime/491666/2 "2021-12-07T12:51:22Z")

</div>

Hey! try call the RegisterComponent function and call AttachToComponent or AttachToActor \*

---

<div class="post-metadata">

**Author:** ![Floydx23](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Floydx23](https://forums.unrealengine.com/u/Floydx23)\
**Post date:** [December 7, 2021, 1:36pm UTC](https://forums.unrealengine.com/t/how-to-create-and-attach-a-uactorcomponent-at-runtime/491666/3 "2021-12-07T13:36:36Z")

</div>

If anyone ever has the same problem as me, you do not need to call AttachToComponent or AttachToActor, you actually can’t (at least from what I know) since this is a UActorComponent. I was just misreading the error RegisterComponent was giving me.  
Anyway thanks for the help!
