CreateDefaultSubobject returns 0

PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
this->AvatarComponent = CreateDefaultSubobject(TEXT(“AvatarComponent”));
this->AddInstanceComponent(this->AvatarComponent);
this->AttributeSet = CreateDefaultSubobject(TEXT(“AvatarAttributeSet”));
if(this->AvatarComponent)
{
UE_LOG(LogTemp, Warning, TEXT(“AvatarComponent is zero after Ctor!”))
}

how may this code run into the print statementß? Any Suggestions on resolving?

Hi Harqui

Create DefaultSubObject can only be called in the classes constructor as it will serialize the component so it can be used with the editor.

If you want to create the components at run time, you will need to spawn them and attach them.
There are many similar questions to this.

Alex