# UPROPERTY is set to null by GC

**URL:** <https://forums.unrealengine.com/t/uproperty-is-set-to-null-by-gc/455464>\
**Category:** C++\
**Tags:** garbage-collector, UProperty, unreal-engine, question, CPP\
**Created:** [September 17, 2019, 8:16am UTC](https://forums.unrealengine.com/t/uproperty-is-set-to-null-by-gc/455464 "2019-09-17T08:16:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_8658d287](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8658d287](https://forums.unrealengine.com/u/anonymous_user_8658d287)\
**Post date:** [September 17, 2019, 8:16am UTC](https://forums.unrealengine.com/t/uproperty-is-set-to-null-by-gc/455464/1 "2019-09-17T08:16:57Z")

</div>

Hi everyone,

I am having a problem with a property that is set to null after constructor finishes. I have a variable of UAttributeSet in my character and it is created in my constructor. This is the code:

```
AEdenValleyCharacterBase::AEdenValleyCharacterBase()
{
  PrimaryActorTick.bCanEverTick = true;

  GetCapsuleComponent()->InitCapsuleSize(45.0f, 96.0f);

  AbilitySystemComp = CreateDefaultSubobject<UAbilitySystemComponent>(TEXT("AbilitySystemComponent"));
  AbilitySystemComp->SetIsReplicated(true);

  AttributeSet = CreateDefaultSubobject<UEdenValleyAttributeSet>(TEXT("AttributeSet"));

  CharacterLevel = 1;
  bAbilitiesInitilized = false;
  bBlockAbilities = false;
}

```

After finishing this part of the code, `AttributeSet` is set to null. This variable is exposed to `UPROPERTY` so GC wouldn’t delete this variable. Also, `AbilitySystemComp` is declared as `AttributeSet`. But, for any reason, only `AttributeSet` is null.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4a30df46](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4a30df46](https://forums.unrealengine.com/u/anonymous_user_4a30df46)\
**Post date:** [November 17, 2020, 10:24am UTC](https://forums.unrealengine.com/t/uproperty-is-set-to-null-by-gc/455464/2 "2020-11-17T10:24:51Z")

</div>

I also met this problem and looking for the solution.Do you figure out the reason ?

---

<div class="post-metadata">

**Author:** ![MexConorZen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MexConorZen](https://forums.unrealengine.com/u/MexConorZen)\
**Post date:** [February 24, 2021, 12:39pm UTC](https://forums.unrealengine.com/t/uproperty-is-set-to-null-by-gc/455464/3 "2021-02-24T12:39:55Z")

</div>

Hey,

Try to use `Instanced` property specifier on your `AttributeSet` property!

```
UPROPERTY(Instanced)
UEdenValleyAttributeSet* AttributeSet;
```

---

<div class="post-metadata">

**Author:** ![FairyTailQZS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FairyTailQZS](https://forums.unrealengine.com/u/FairyTailQZS)\
**Post date:** [October 3, 2021, 4:46pm UTC](https://forums.unrealengine.com/t/uproperty-is-set-to-null-by-gc/455464/4 "2021-10-03T16:46:25Z")

</div>

I have the same problem. Have you solved it?

---

<div class="post-metadata">

**Author:** ![ng\_sbourgoing](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ng\_sbourgoing](https://forums.unrealengine.com/u/ng_sbourgoing)\
**Post date:** [October 30, 2021, 11:42am UTC](https://forums.unrealengine.com/t/uproperty-is-set-to-null-by-gc/455464/5 "2021-10-30T11:42:40Z")

</div>

Hello there,

I have hit the same problem with AttributeSet on my side, and the solution been to use the specifier transient

```
 UPROPERTY(transient)
MyAttributeSet* AttributeSet;

```

Let me know if that work, Have a nice day !

---

<div class="post-metadata">

**Author:** ![Linqen](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/linqen/32/924597_2.png) [@Linqen](https://forums.unrealengine.com/u/Linqen)\
**Post date:** [January 11, 2024, 2:35am UTC](https://forums.unrealengine.com/t/uproperty-is-set-to-null-by-gc/455464/6 "2024-01-11T02:35:48Z")

</div>

This is the answer!

I have been facing a crash because the attribute set was null on duplicated BPs.

Thanks a lot!
