I can create Components using PCIP::CreateDefaultSubobject but I need to create a parametric Actor, lets say a matrix of spheres in which I can change the Rows and Colums in the editor. I’m using PostEditChangeProperty to catch when the parameters are changed but I cannot find how to add or remove the MeshComponents.
Can anyone help me understand how to create a hierarchy with dynamic container with n meshes?
Finally after a lot of debug into the engine I found a solution. Here’s a code sample that works so far. I don’t know if this is safe and leak-free but it’s a starting point.
AMyActor::AMyActor(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
RootComponent = ConstructObject<USphereComponent>(
USphereComponent::StaticClass(), this, TEXT("sphere"));
}
void AMyActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
auto box = ConstructObject<UBoxComponent>(
UBoxComponent::StaticClass(), this, TEXT("box"));
box->SetFlags(RF_DefaultSubObject);
box->AttachTo(RootComponent);
RegisterAllComponents();
Super::PostEditChangeProperty(PropertyChangedEvent);
}