Fix PackedLevelActor not showing correct names

One of my other gripe with PackedLevelActor is that all the InstancedStaticMesh components lose their name correspondence with their StaticMeshActor counterpart.

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.

Come on guys its such an easy fix:

	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;
	}
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);
	PackComponent->AttachToComponent(PackingActor->GetRootComponent(), FAttachmentTransformRules::SnapToTargetIncludingScale);

1 Like