# Component pointer invalid after creation in class constructor

**URL:** <https://forums.unrealengine.com/t/component-pointer-invalid-after-creation-in-class-constructor/153652>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [November 15, 2020, 1:22am UTC](https://forums.unrealengine.com/t/component-pointer-invalid-after-creation-in-class-constructor/153652 "2020-11-15T01:22:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [November 15, 2020, 1:22am UTC](https://forums.unrealengine.com/t/component-pointer-invalid-after-creation-in-class-constructor/153652/1 "2020-11-15T01:22:05Z")

</div>

Hi,

I m adding a component to character class by using a\_pointer\_declare\_in.h = CreateDefaultSubobject(TEXT(“Somename”));

But once the game start and using bp to check if a\_pointer\_declare\_in.h is valid i got false do i miss some steps to get it work?

More than this in detail panel i can t see properties mark as editanywhere.

When i add the component with addcomponent button in blueprint editor those components are valid.

Any idea on the problem?

In the character .h

1. UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Inventory, meta = (AllowPrivateAccess = “true”))
2. class UPlayerInventory\* PlayerInventory;

In the character .cpp constructor:

1. PlayerInventory = CreateDefaultSubobject\<UPlayerInventory\>(TEXT(“PlayerInventory”));

Class declaration & propery declaration:

1. UCLASS(Blueprintable, BlueprintType, meta=(BlueprintSpawnableComponent))
2. class MYPROJECT\_API UPlayerInventory : public UActorComponent
3. GENERATED\_BODY()
4. UPROPERTY(EditAnywhere, Category = “Inventory”)
5. int32 MaxSlots;

EDIT: i have the exact same problem of this guy: [https://www.reddit.com/r/unrealengine/comments/bss70y/how\_to\_create\_a\_custom\_uactorcomponent\_properly/eopr7r8/](https://www.reddit.com/r/unrealengine/comments/bss70y/how_to_create_a_custom_uactorcomponent_properly/eopr7r8/)

---

<div class="post-metadata">

**Author:** ![KelbyVP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kelbyvp/32/261024_2.png) [@KelbyVP](https://forums.unrealengine.com/u/KelbyVP)\
**Post date:** [November 16, 2020, 4:46am UTC](https://forums.unrealengine.com/t/component-pointer-invalid-after-creation-in-class-constructor/153652/2 "2020-11-16T04:46:07Z")

</div>

That looks right for the C++ code. Can you show the BP nodes you are using to check the pointer?
