# Component Created in C++ is destroyed before BeginPlay

**URL:** <https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [August 28, 2019, 11:33pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545 "2019-08-28T23:33:18Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_e4a57402](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e4a57402](https://forums.unrealengine.com/u/anonymous_user_e4a57402)\
**Post date:** [August 28, 2019, 11:33pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/1 "2019-08-28T23:33:18Z")

</div>

Following [this](https://wiki.unrealengine.com/GameplayAbilities_and_You#Binding_to_Character_Input) tutorial, I am adding the Gameplay Abilities System to my game.

I add the `UAbilitySystemComponent` to the `AAbilityCharacter` class in the header like so:

```
/// Interface to the gameplay ability system
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess), Category = Abilities)
UAbilitySystemComponent* AbilitySystem;

```

And create the component in the constructor like so:

```
// Component which we use to interface to the ability system
AbilitySystem = CreateDefaultSubobject<UAbilitySystemComponent>(TEXT("Ability System"));

```

However, by logging from `SetupPlayerInputComponent` and `BeginPlay`, it seems that the component no longer exists!

```
LogTemp: Display: Ability System Missing in SetupPlayerInputComponent
LogTemp: Display: Ability System Missing in BeginPlay

```

This was previously causing crashes when I tried to bind the ability system to PlayerInput.

The `AbilitySystem` shows up as an inherited component when I open the derived blueprint class in the editor:

![286106-ability-system.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/a/5/9a5aef2fcc071916b0214a52b6923f1ccabb53ee.png)

But it does not have any properties that I can edit:

![286107-details-pane.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/5/5/35581fa6d3c0a1508f3d486b6d479e98663ba033.png)

But when the AbilitySystem is added with the “New Component” button it’s details pane looks like so:

![286108-normal.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/9/d/49d720bc85946fa63ecf6ea916bc246b897dc874.png)

I am at my wits end trying to solve this issue. I am using the Advanced Locomotion Plugin but I re-parented it to my C++ class. However, when I reparent the final blueprint class I am using to the `AAbilityCharacter` the problem persists. It also appears to extend to _any_ non `SceneComponent` I create, and I have not tired to replicate this issue with a `SceneComponent`.

What could have caused this? I have tried a variety of approaches to track down the problem, but I can’t even figure out exactly where in the life-cycle the component is deleted except that it’s _before_ `SetupPlayerInputComponent`

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e4a57402](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e4a57402](https://forums.unrealengine.com/u/anonymous_user_e4a57402)\
**Post date:** [August 29, 2019, 12:48am UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/2 "2019-08-29T00:48:42Z")

</div>

Changing the name of the component variable fixed the issue somehow, but I would still like to know why!

---

<div class="post-metadata">

**Author:** ![NorthWeapon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NorthWeapon](https://forums.unrealengine.com/u/NorthWeapon)\
**Post date:** [October 30, 2020, 7:51pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/3 "2020-10-30T19:51:24Z")

</div>

God is Great! This fixed the problem, I commend you for letting the rest of us know of this absolutely strange behavior.

I admittedly spent more than 10 hours trying to figure this out.

My original PlayerState had this:

`class UHarbAbilitySystemComponent* AbilitySystemComponent;`

I renamed it to:

`class UHarbAbilitySystemComponent* GameplayAbilitySystemComponent;`

And my breakpoints now show that the component is in fact not `Null` anymore.

Upvoted answer

---

<div class="post-metadata">

**Author:** ![NorthWeapon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NorthWeapon](https://forums.unrealengine.com/u/NorthWeapon)\
**Post date:** [October 30, 2020, 7:52pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/4 "2020-10-30T19:52:22Z")

</div>

I’m curious, what made you even try to change the variable name? That’s where I’d least expect to cause the bug… a variable name?

---

<div class="post-metadata">

**Author:** ![Imonin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Imonin](https://forums.unrealengine.com/u/Imonin)\
**Post date:** [April 12, 2021, 1:47am UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/5 "2021-04-12T01:47:51Z")

</div>

Holy ■■■■… I have been having this problem for days… the exact same thing. I changed the name to what you did… Copy past from this post and bam… it works. I would have never figured this out without you.

---

<div class="post-metadata">

**Author:** ![NovanMK2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NovanMK2](https://forums.unrealengine.com/u/NovanMK2)\
**Post date:** [May 26, 2021, 4:12pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/6 "2021-05-26T16:12:31Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_22d1f222](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_22d1f222](https://forums.unrealengine.com/u/anonymous_user_22d1f222)\
**Post date:** [June 18, 2021, 3:44am UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/7 "2021-06-18T03:44:27Z")

</div>

Thanks for the answer! I just had this same issue in **4.26.2** and this resolved it.

---

<div class="post-metadata">

**Author:** ![K3Z4](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/k3z4/32/491638_2.png) [@K3Z4](https://forums.unrealengine.com/u/K3Z4)\
**Post date:** [November 1, 2021, 6:12pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/8 "2021-11-01T18:12:45Z")

</div>

Happened to me too, 4.26.2. Had to rename a spring arm component to get it working again.

---

<div class="post-metadata">

**Author:** ![JediKnightChan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jediknightchan/32/1156960_2.png) [@JediKnightChan](https://forums.unrealengine.com/u/JediKnightChan)\
**Post date:** [December 3, 2022, 10:47pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/9 "2022-12-03T22:47:52Z")

</div>

It is not an issue of GAS, it’s a common UE issue thay are too busy messing with Nanites and other \*\*\*\* to fix

> [@Changing a default subobject name in C++ class leads to UActorComponent being marked as PendingKill immediately after being instantiated when loading from .uasset, and is eventually reset to NULL by GC](https://forums.unrealengine.com/t/changing-a-default-subobject-name-in-c-class-leads-to-uactorcomponent-being-marked-as-pendingkill-immediately-after-being-instantiated-when-loading-from-uasset-and-is-eventually-reset-to-null-by-gc/480745):
>
> Short Description So, I’ve been investigating this bug for quite some time. I have also found several posts on UE forums on this issue. It affects several engine versions – I have personally reproduced it on 4.25.4 and 4.26.1 (using both Launcher version and recompiled from source). The issue happens only with blueprints. There are 2 symptoms I know of: UPROPERTY() component pointer is somehow set to NULL in BeginPlay() though it has been set to a non-NULL object in C++ constructor using Cr…

> [@UPROPERTY member vars reset to NULL by ObjectInitializer](https://forums.unrealengine.com/t/uproperty-member-vars-reset-to-null-by-objectinitializer/19959/17):
>
> It looks like I figured out what’s going on: In order for the properties of components to be saved when loading the level, it is necessary that they are created in the actor constructor, and their CreationMethod must be equal to EComponentCreationMethod::Native (this value is set by default when creating a new component using CrteateDefaultSubobject()). If components are created in the OnConstruction() method and their CreationMethod = EComponentCreationMethod::UserConstructionScript, then the…

---

<div class="post-metadata">

**Author:** ![UNIT28Studios](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/unit28studios/32/1142186_2.png) [@UNIT28Studios](https://forums.unrealengine.com/u/UNIT28Studios)\
**Post date:** [October 1, 2023, 5:51pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/10 "2023-10-01T17:51:38Z")

</div>

I’ve had this exact same problem. Renaming the component variable name _does_ fix the issue, but I find it’s only temporary. If I continue making changes to the surrounding code, it tends to eventually crop up again.

---

<div class="post-metadata">

**Author:** ![adoillmc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adoillmc](https://forums.unrealengine.com/u/adoillmc)\
**Post date:** [October 5, 2023, 1:24pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/11 "2023-10-05T13:24:48Z")

</div>

![170050](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/0/f/70f82c72391732b56eb2b2e7fe761a63bb7f1773.jpeg)

I just dragged the component to the graph, and reset it to default value, it worked for me.

---

<div class="post-metadata">

**Author:** ![aallfik11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aallfik11](https://forums.unrealengine.com/u/aallfik11)\
**Post date:** [May 6, 2024, 12:35pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/12 "2024-05-06T12:35:10Z")

</div>

I thought I was going insane, I’m so glad I found this thread, thank you guys!

---

<div class="post-metadata">

**Author:** ![jebeno\_fish1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jebeno\_fish1](https://forums.unrealengine.com/u/jebeno_fish1)\
**Post date:** [February 22, 2025, 5:22pm UTC](https://forums.unrealengine.com/t/component-created-in-c-is-destroyed-before-beginplay/454545/13 "2025-02-22T17:22:59Z")

</div>

Thank you for your sacrifice. You just saved me over 10 hours of head banging 🙂 as a quick sidenote, it appears that the only forbiden name might be ‘AbilitySystemComponent’. I changed mine to ‘CharacterASC’ and it still works. Bless you good man \<3
