Spend the whole day for finding a solution for my proplem, but haven´t any luck to get this working.
A BodyComponent (USkeletalMeshComponent) having the mesh and the animation is working fine. I now want to attach another component to it as a dummy UClothesComponent (USkeletalMeshComponent) which should hold an TArray of SkeletalMeshComponents for clothing. Clothing is added to the body and moving with it, but clothes never get animation. I think thats because animation of BodyComponent is not transferred to UClothesComponent, which has no skeletal data, so that the clothes even don´t get animation data.
If i would attach one of the clothes directly to BodyComponent it is being animated and synched to the body animation. So my question is: What i am missing here? Is there a better way, a working one, to have a clean component-structure and ChildComponents being animated with the a ParentComponent?
Code of the Female.cpp file
BodyComponent = ObjectInitializer.CreateDefaultSubobject<UFemaleBodyComponent>(this, TEXT("BodyComponent"));
BodyComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
BodyComponent->SetMobility(EComponentMobility::Movable);
BodyComponent->SetWorldRotation(RotateOffset);
BodyComponent->SetRelativeLocation(FVector(0.0f, 0.0f, -90.0f));
BodyComponent->bDisableMorphTarget = false;
ClothesComponent = ObjectInitializer.CreateDefaultSubobject<UClothesComponent>(this, TEXT("ClothesComponent"));
ClothesComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
ClothesComponent->SetMobility(EComponentMobility::Movable);
ClothesComponent->SetWorldRotation(RotateOffset);
ClothesComponent->SetRelativeLocation(FVector(0.0f, 0.0f, -90.0f));
ClothesComponent->bDisableMorphTarget = false;
Code of the UClothesComponent.cpp
UClothesComponent::UClothesComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
PrimaryComponentTick.bCanEverTick = true;
int counter = 0;
for (auto temp : UGarments::ArrGarments)
{
counter++;
GarmentComponents.Add(ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, *FString("Cloth" + FString::FromInt(counter))));
}
for (int i=0; i<counter;i++) {
ConstructorHelpers::FObjectFinder<USkeletalMesh> Asset(*UGarments::ArrGarments[i].Path);
if (Asset.Succeeded())
{
GarmentComponents[i]->SetSkeletalMesh(Asset.Object);
}
GarmentComponents[i]->AttachToComponent(this, FAttachmentTransformRules::KeepWorldTransform);
GarmentComponents[i]->SetMobility(EComponentMobility::Movable);
}