I create a modular building from hierarchical static mesh components in C++. When I copy the building, it copies the old instances and doesn’t remove them when parameters change. So basically after copying I get the old building inside my new actor, and when I change parameters like width or heights. Another building apperas intersecting the old one. How do I remove “old” instance so to say OnCopy and recalculate my one based on parameters? Or maybe how do I copy the Actor and its parameters only without copying existing instances?
So I found a way to remove instances. In the beginning of my onConstruction I call →
auto comps = GetComponents();
for (UActorComponent* Component : comps) {
UHierarchicalInstancedStaticMeshComponent* HierarchicalISMC = Cast<UHierarchicalInstancedStaticMeshComponent>(Component);
if (HierarchicalISMC) {
HierarchicalISMC->ClearInstances();
}
}
However, each time I change my Actor parameters there are more and more Components with type UHierarchicalInstancedStaticMeshComponent found. Looks weird.