# how can i add 'actor component' in run time?

**URL:** <https://forums.unrealengine.com/t/how-can-i-add-actor-component-in-run-time/348938>\
**Category:** Community & Industry Discussion\
**Tags:** actor-component, add, unreal-engine, dynamic, runtime, question\
**Created:** [February 28, 2016, 7:31am UTC](https://forums.unrealengine.com/t/how-can-i-add-actor-component-in-run-time/348938 "2016-02-28T07:31:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_1111614c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1111614c](https://forums.unrealengine.com/u/anonymous_user_1111614c)\
**Post date:** [February 28, 2016, 7:31am UTC](https://forums.unrealengine.com/t/how-can-i-add-actor-component-in-run-time/348938/1 "2016-02-28T07:31:08Z")

</div>

i made ‘actor component’ type ‘FlyWithRocket’ ‘FlyWithWing’

and i met a beautiful rock in my adventure.

now i want to make it fly with mighty rocket power!! (seriously?)

how can add ‘flyWithRocket’ actor component to rock?

i tried with ‘construct object with class’ but it not works.

help!

 ![80266-cannot+construct+actor+component.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/3/7/3378966a9323ae72a27caa5398832d5325f47d52.png)

---

<div class="post-metadata">

**Author:** ![cmann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cmann](https://forums.unrealengine.com/u/cmann)\
**Post date:** [May 16, 2016, 10:59am UTC](https://forums.unrealengine.com/t/how-can-i-add-actor-component-in-run-time/348938/2 "2016-05-16T10:59:07Z")

</div>

I think you’ll have to do it with C++.  
See [here](https://forums.unrealengine.com/showthread.php?52410-What-is-the-correct-way-to-create-and-add-components-at-runtime) or [here](https://answers.unrealengine.com/questions/286630/component-added-at-runtime-doesnt-have-beginplay-c.html).

The code from link #2:

```
//Adds a UActorComponent Subclass, that is based on the passed in Class, and added to the Outer(Actor) object
 UActorComponent* UFSBlueprintFunctionLibrary::AddComponentByClass(TSubclassOf<UActorComponent> Class, UObject* Outer)
 {
     if (Class != nullptr && Outer != nullptr)
     {
         UActorComponent* Component = NewObject<UActorComponent>(Outer, *Class);
         if (Component != nullptr)
         {
             Component->RegisterComponent();
             return Component;
         }
         else
         {
             return nullptr;
         }
     }
 
     return nullptr;
 }

```
