Component Created in C++ is destroyed before BeginPlay

Following this 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

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

286107-details-pane.png

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

286108-normal.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

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

1 Like

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

1 Like

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?

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.

Thank you!

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

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

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

2 Likes

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.

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

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