Hello, i tried implementing a way that allows me to dynamically add multiple SkeletalMeshComponents for an Actor. My idea was having an array that would have a fixed size and then on the constructor i would create a SkeletalMeshComponent to place on each index. The index 0 will be the Root Component. Here is the code:
Header:
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Item")
TArray<class USkeletalMeshComponent *> Meshes;
Cpp:
ATest::ATest(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
Meshes.Init(2);
for (int32 i = 0; i < Meshes.Num(); i++)
{
FName Name = TEXT("Mesh");
if (i > 0)
Name = FName(*(FString::Printf(TEXT("Mesh_%d"), i)));
Meshes[i] = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, Name);
if (i == 0)
RootComponent = Meshes[i];
else Meshes[i]->AttachParent = Meshes[0];
}
}
When i create a new blueprint based of that class i see the RootComponent listed as well as Mesh_1, but if i click them the details panel doesn’t show anything, so they’re useless. What did i do wrong? Thank you