Component as UPROPERTY with default value = NULL declared in base cpp class and edited in blueprint child class is reset to null after blueprint compilation

Hello

I have an actor base class AProjectile where i declare a property named “ProjectileMesh”

UPROPERTY(EditDefaultsOnly, Category = PlayerProjectile, meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* ProjectileMesh;

I have a blueprint class LaserProjectile which inherit of AProjectile
When i try to modify the “ProjectileMesh” property (“NONE” to Something else) value it works until i click on “compile blueprint” then the property is reset to “NONE”

I tried to write some code to register correctly the component when the property is modified

void AProjectile::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
	Super::PostEditChangeProperty(PropertyChangedEvent);
	
	if(PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(AProjectile, ProjectileMesh))
	{
		if (ProjectileMesh && !ProjectileMesh->IsAttachedTo(RootComponent))
		{
				ProjectileMesh->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
				ProjectileMesh->RegisterComponent();
		}
		else if (!ProjectileMesh)
		{
				// how to unregister ??
		}
	}
}

but it doesn’t solve the problem :confused:

EDIT

OK it seems it’s not really handled by default :/…

One simple solution I see is to store the data needed to instantiate the dynamic component (or not) in other properties
ex : if user init or change the variable
UProperty()
class UStaticMesh StaticMesh

then i can detect and create/destroy a dynamic component , and change if needed the mesh on the component

but this solution means if i want extensive customization of the dynamic component i needed to copy a lot of fields already present in the component …