Compiling clears the value of inline objects set in blueprint details panel

I have a USceneComponent called UInteractionTrigger. It has a UPrimitiveComponent as a UProperty that is edited inline in the details panel.

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Interaction)
UPrimitiveComponent* InteractionCollider;

Now, if I add it to a Actor in blueprint, I am able to edit the values and everything works fine.
But, if I add it from cpp as follows,

In WeaponBase.h,

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Weapon | Default")
UInteractionTrigger* InteractionTrigger;

In WeaponBase.cpp in the constructor,
InteractionTrigger = CreateDefaultSubobject<UInteractionTrigger>(TEXT("Interaction Trigger"));

If i edit the value in a child blueprint of WeaponBase.h, the value if being reset every time I press compile.

  • I am setting the Interaction collider value as Box collision from details panel and value is getting reset to none
  • Like this,

I am not sure if it is a bug in unreal editor or if something is wrong in my code, though I am not manually setting the value to nullptr anywhere in my code.

Old thread, but if anyone is still having this problem, I found a solution. Manually adding “Instanced” to the UProperty fixes it. Example:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Weapon | Default", Instanced)
UInteractionTrigger* InteractionTrigger;

It seems “DefaultToInstanced” is buggy with blueprint classes, so always manually declare UProperties as “Instanced” if they’re going to be editable in blueprint subclasses. I recommend avoiding DefaultToInstanced unless the class is only ever going to be referenced in non-Blueprintable classes.