# What is the correct way to create and add components at runtime ?

**URL:** <https://forums.unrealengine.com/t/what-is-the-correct-way-to-create-and-add-components-at-runtime/15605>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [November 20, 2014, 5:40pm UTC](https://forums.unrealengine.com/t/what-is-the-correct-way-to-create-and-add-components-at-runtime/15605 "2014-11-20T17:40:42Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![Demeese](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Demeese](https://forums.unrealengine.com/u/Demeese)\
**Post date:** [October 27, 2022, 8:00pm UTC](https://forums.unrealengine.com/t/what-is-the-correct-way-to-create-and-add-components-at-runtime/15605/21 "2022-10-27T20:00:33Z")

</div>

I’m using Unreal5, but what i’ve found is the AddComponentByClass();

```auto
AddComponentByClass(TSubclassOf<UActorComponent> Class, bool bManualAttachment, const FTransform& RelativeTransform, bool bDeferredFinish)

and for example:

AddComponentByClass(UMyComponent::StaticClass, false, SpawnTransform, false);

```

This uses the NewObject method and will register your component.

---

<div class="post-metadata">

**Author:** ![VeryCh1lorine](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VeryCh1lorine](https://forums.unrealengine.com/u/VeryCh1lorine)\
**Post date:** [April 13, 2023, 2:29am UTC](https://forums.unrealengine.com/t/what-is-the-correct-way-to-create-and-add-components-at-runtime/15605/22 "2023-04-13T02:29:48Z")

</div>

I’m trying to convert a CreateComponentByClass Blueprint Node to C++, I‘m not sure if it’s appropriate. Because the blueprint Node only have two Pin.

[Previous page](https://forums.unrealengine.com/t/what-is-the-correct-way-to-create-and-add-components-at-runtime/15605.md?page=1)
