I’m making a TArray<UStaticMeshComponent*> in my actor’s constructor. At the end of the constructor, it has 6 items.
But when BeginPlay() calls, it has one NULL item. What’s wrong?
in ShipEngines.h:
UPROPERTY(BlueprintReadOnly, Category = "Engines")
TArray<UStaticMeshComponent*> Engines;
in ShipEngines.cpp:
AShipEngines::AShipEngines()
{
Root = CreateDefaultSubobject<USceneComponent>(FName("Root"));
Root->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
for (int i = 0; i < 6; i++)
{
UStaticMeshComponent* EngineComponent = CreateDefaultSubobject<UStaticMeshComponent>(FName(FString::Printf(TEXT("EngineComponent_%i"), i)));
EngineComponent->AttachToComponent(Root, FAttachmentTransformRules::KeepRelativeTransform);
Engines.Add(EngineComponent);
}
//Engines has 6 items
}
void AShipEngines::BeginPlay()
{
Super::BeginPlay();
//Engines has 1 item, and it is NULL
}