One of my other gripe with PackedLevelActor is that all the InstancedStaticMesh components lose their name correspondence with their StaticMeshActor counterpart present in the Level. In the example shown below, I have renamed a InstancedStaticMesh to show what I mean.
This makes it difficult to write construction script referring to the components. I believe the problem is due to how, unlike actors, components do not have distinct names and label. Introducing component label would be one way to fix it, or simply assigning the label as a component would be another way to look at it.
Packed Level Actor:
Level:
I believe the engine could do something like this:
// PackedLevelActorISMBuilder.cpp
uint32 FPackedLevelActorISMBuilder::PackActors(FPackedLevelActorBuilderContext& InContext, const FPackedLevelActorBuilderClusterID& InClusterID, const TArray<UActorComponent*>& InComponents) const
{
...
FName ComponentName = NAME_None;
if (InComponents.Num() > 0)
ComponentName = FName(*InComponents[0]->GetOwner()->GetActorLabel());
UInstancedStaticMeshComponent* PackComponent = PackingActor->AddPackedComponent<UInstancedStaticMeshComponent>(ComponentClass, ComponentName);
...
}
// PackedLevelActor.h
template<class T>
T* AddPackedComponent(TSubclassOf<T> ComponentClass, const FName& InComponentName = NAME_None)
{
Modify();
FName NewComponentName = InComponentName == NAME_None ? *FComponentEditorUtils::GenerateValidVariableName(ComponentClass, this) : InComponentName;
T* NewComponent = NewObject<T>(this, ComponentClass, NewComponentName, RF_Transactional);
AddInstanceComponent(NewComponent);
NewComponent->ComponentTags.Add(GetPackedComponentTag());
return NewComponent;
}