Array of components

I’m trying to create an array of components.
However, each time I add new elements to an array in the constructor, they are simply not added. And when I compile the code, I get an error message that you have gone beyond the array (although this can not be).

This is my code:

UProceduralMeshComponent* section_1 = CreateDefaultSubobject <UProceduralMeshComponent>(TEXT("Infinity"));
    RootComponent = mesh[0];

    UProceduralMeshComponent* section_2 = CreateDefaultSubobject <UProceduralMeshComponent>(TEXT("Infinity2"));
    section_2->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);

    UProceduralMeshComponent* section_3 = CreateDefaultSubobject <UProceduralMeshComponent>(TEXT("Infinity3"));
    section_3->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);

From the code you can see that I added three elements.
However, the third element and more he does not add and errors appear.


What does the declaration for your mesh variable look like.

It should be something like TArray<UProicedueralMeshComponent *> mesh;

Yep, so:

UPROPERTY(EditAnywhere, Instanced)
        TArray <class UProceduralMeshComponent*> mesh;