# How to create a custom UActorComponent properly?

**URL:** <https://forums.unrealengine.com/t/how-to-create-a-custom-uactorcomponent-properly/449553>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 25, 2019, 8:18am UTC](https://forums.unrealengine.com/t/how-to-create-a-custom-uactorcomponent-properly/449553 "2019-05-25T08:18:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomza](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tomza](https://forums.unrealengine.com/u/Tomza)\
**Post date:** [May 25, 2019, 8:18am UTC](https://forums.unrealengine.com/t/how-to-create-a-custom-uactorcomponent-properly/449553/1 "2019-05-25T08:18:14Z")

</div>

Hi all,

I have the following code in .H:

```
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Custom Actor Components")
class UMyActorComponent* MyActorComponent;

```

and in the constructor of .CPP:

```
MyActorComponent = CreateDefaultSubobject<UMyActorComponent>(TEXT("MyActorComponent "));

```

The MyActorComponent pointer is not initialized. WHY???

---

<div class="post-metadata">

**Author:** ![danielf94](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@danielf94](https://forums.unrealengine.com/u/danielf94)\
**Post date:** [May 25, 2019, 9:15pm UTC](https://forums.unrealengine.com/t/how-to-create-a-custom-uactorcomponent-properly/449553/2 "2019-05-25T21:15:51Z")

</div>

Hello! it’s like that:

.h

```
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Custom Actor Components")
class UActorComponent* MyActorComponent;

```

.cpp

```
MyActorComponent = CreateDefaultSubobject<UActorComponent>(TEXT("MyActorComponent "));

```

includes the library in the .cpp:

```
#include "Components/ActorComponent.h"

```

–

you are typing the name of your class in the class type! do not forget to mark the answer as correct

---

<div class="post-metadata">

**Author:** ![Tomza](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tomza](https://forums.unrealengine.com/u/Tomza)\
**Post date:** [May 26, 2019, 5:53am UTC](https://forums.unrealengine.com/t/how-to-create-a-custom-uactorcomponent-properly/449553/3 "2019-05-26T05:53:33Z")

</div>

Thank you for your answer, but I need to create my custom actor component (UMyActorComponent), not UActorComponent. It seems you are creating UActorComponent. UMyActorComponent is a child of UActorComponent.

---

<div class="post-metadata">

**Author:** ![TheDreamCatcher](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/thedreamcatcher/32/727178_2.png) [@TheDreamCatcher](https://forums.unrealengine.com/u/TheDreamCatcher)\
**Post date:** [May 26, 2019, 7:29pm UTC](https://forums.unrealengine.com/t/how-to-create-a-custom-uactorcomponent-properly/449553/4 "2019-05-26T19:29:45Z")

</div>

so first you need to create an ActorComponent class that derives from UActorComponent. Then you can add this newly created ActorComponent to your actor.

---

<div class="post-metadata">

**Author:** ![Tomza](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tomza](https://forums.unrealengine.com/u/Tomza)\
**Post date:** [May 27, 2019, 7:08am UTC](https://forums.unrealengine.com/t/how-to-create-a-custom-uactorcomponent-properly/449553/5 "2019-05-27T07:08:31Z")

</div>

I know that I can have my custom component deriving from UActorComponent and then I can add it manually to a an AActor BP, but how to do that in C++ only? I mean creating like other components in UE4 with using CreateDefaultSubobject.

---

<div class="post-metadata">

**Author:** ![mrm\_dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mrm\_dev](https://forums.unrealengine.com/u/mrm_dev)\
**Post date:** [December 31, 2024, 8:36pm UTC](https://forums.unrealengine.com/t/how-to-create-a-custom-uactorcomponent-properly/449553/6 "2024-12-31T20:36:01Z")

</div>

Any Updates? I’ve run into the same problem on Version 5.4

---

<div class="post-metadata">

**Author:** ![LeBerberes](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LeBerberes](https://forums.unrealengine.com/u/LeBerberes)\
**Post date:** [January 29, 2025, 12:10pm UTC](https://forums.unrealengine.com/t/how-to-create-a-custom-uactorcomponent-properly/449553/7 "2025-01-29T12:10:03Z")

</div>

Same problem RN in 5.3.2
