UObject in TArry garbage if created in constructor

Hi,

I you add some New UObject in constructor in a Tarray (UPROPERY), they are garbagged.
If you do the same code in PostInitComponents, they are not garbagged.

Could you please confirm this is a bug or something by design?

Thanks,

What are you adding in to array exacly? Do you really need to do that in constructor?

My UObject are “Player Attributes” that I use to compute speed or max health.

I’m not force to do it in the constructor, but are those attributes are the default one, why shouldn’t I do that in the constructor like I set other default variables values?

So I have a workaround for the moment, but what I want is to understand the purpose of this behavior bug or design. If design, I will appreciate to learn why.

Thanks,

Ahhh use struct insted of class then for attributes :slight_smile: Constructor is not good envriament for UObject where things are not yet initiated

Even if struct are better or not… (I keep your advice in mind) … it’s not the question here. The question is more does anyone else face this issue or is it link to my code?

I will just add some clarify to help reproducing the bug.

My Tarray in in a Component.
This component is created in the Character Constructor and then I’m adding some UObject in it.
Then it fails.

If I’m using the PostInitComponents of my Character class, it’s fine.

Thanks,