AttachToComponent several meshes for one socket

So I want to use AttachToComponent for multiple meshes and one socket, but it doesn’t allow me to do that. However, in Blueprints you can easily attach several meshes in one socket (in the Components tab I mean)

So it’s possible to achieve that if you know how the blueprint is constructed well.

My code:


template <class SceneComponentClass>
SceneComponentClass* UCustomizationLoaderComponent::SpawnChildComponent(USkeletalMeshComponent* Component,
                                                                        const FString Name, const FName SocketName = "")
{
	SceneComponentClass* ChildComponent = NewObject<SceneComponentClass>(
		Component, SceneComponentClass::StaticClass(), FName{Name});

	ChildComponent->RegisterComponent();
	if (SocketName != "" && SocketName != "None")
	{
		UE_LOG(LogTemp, Warning, TEXT("Attaching component %s to socket %s"), *(GetNameSafe(ChildComponent)),
		       *(SocketName.ToString()))
		ChildComponent->AttachToComponent(Component, FAttachmentTransformRules::SnapToTargetIncludingScale,
		                                  SocketName);
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("No socket for component %s"), *(GetNameSafe(ChildComponent)))
		ChildComponent->AttachToComponent(Component, FAttachmentTransformRules::SnapToTargetIncludingScale);
	}
	ChildComponent->CreationMethod = EComponentCreationMethod::Instance;
	return ChildComponent;
}

For now I ended up cloning sockets (several ones for one location) as I don’t need to attach too many meshes