# Proper way to add custom actor component

**URL:** <https://forums.unrealengine.com/t/proper-way-to-add-custom-actor-component/359465>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 3, 2016, 5:03am UTC](https://forums.unrealengine.com/t/proper-way-to-add-custom-actor-component/359465 "2016-06-03T05:03:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boagz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Boagz](https://forums.unrealengine.com/u/Boagz)\
**Post date:** [June 3, 2016, 5:03am UTC](https://forums.unrealengine.com/t/proper-way-to-add-custom-actor-component/359465/1 "2016-06-03T05:03:19Z")

</div>

Hi! So after stumbling upon this post:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

I went ahead and tried adding my own custom character movement component to my custom character class. I was successful for the most part but have a few questions.

In the wiki article he has, within the custom movement component’s header file, defined:

```
virutal void InitializeComponent() overrrive;

```

with the .cpp implementation like so:

```
void UCustomMovementComponent::InitializeComponent()
{
	Super::InitializeComponent();
	// ~~~~~~~~~~~~~~~~~
 
	//UE_LOG //comp Init!
}

```

My question is where I’m I suppose to call the InitializeComponent() function? Or in what situations do I even need to call it? When I place this function within my custom movement component’s constructor UE4 crashes so I don’t think that is the place. Any insight on this issue would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Nachtmahr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nachtmahr](https://forums.unrealengine.com/u/Nachtmahr)\
**Post date:** [June 3, 2016, 9:49pm UTC](https://forums.unrealengine.com/t/proper-way-to-add-custom-actor-component/359465/2 "2016-06-03T21:49:11Z")

</div>

That should be called for you under the hood.

Test it out with:

```
UE_LOG(LogTemp, Warning, TEXT("Custom Component Init Called"));

```

If you look at your OutputLog inside the Engine you know the exact point when its called. But if you dont need the function you can delete it.

Edit: I just noticed in the Tutorial it does never show how to Set the Component.In your Constructor:

```
GetCharacterMovement() = CreateDefaultSubobject<UCustomMovementComponent>(ACharacter::CharacterMovementComponentName);
	if (GetCharacterMovement())
	{
		GetCharacterMovement()->UpdatedComponent = GetCapsuleComponent();
		CrouchedEyeHeight = GetCharacterMovement()->CrouchedHalfHeight * 0.80f;
	}

```

Same way as it is Set in the ACharacter. Use the Cast to access your Specific Typed UCustomMovementComponent.

Good Luck and have Fun =)
