UStaticMeshComponent* Spike = CreateDefaultSubobject(TEXT(“Spike”));
Spike->GetComponentLocation() = NewLocation;
static ConstructorHelpers::FObjectFinder SpikeAsset(TEXT(“StaticMesh’/Game/StarterContent/Shapes/Shape_Cone.Shape_Cone’”));
UStaticMeshComponent* Spikes = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Spikes"));
for (int x = 0; x<10; x++){
//I want to create 10 extra spikes with the loop, but how?
UStaticMeshComponent* Spikes = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Spikes"));
//Attaching them to my root component
Spikes->SetupAttachment(Spike);
//Moving them 100 x
Spikes->SetRelativeLocation(NewLocation += FVector(100, 0, 0));
if (SpikeAsset.Succeeded()) {
Spike->SetStaticMesh(SpikeAsset.Object);
//adding shape to all my units
Spikes->SetStaticMesh(SpikeAsset.Object);
}
}
What I basically want to do here is create 10 more spikes with a for loop.
How do I add 10 static mesh components with a for loop?