Im trying to make a map. I made a class which inherit from pawn. I add several cube on the constructor but it crash when I add too much cubes. Let’s take the following code:
int WIDTH_MAP = 13;
int HEIGHT_MAP = 13;
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
this->SetActorLocation(FVector(0.f, 0.f, 0.f));
//this->RootComponent->SetWorldLocation(FVector(0.f, 0.f, 0.f));
//Create blocks
for (int i = 1; i < WIDTH_MAP; i += 2) {
for (int j = 1; j < HEIGHT_MAP; j +=2) {
FString s = FString::FromInt(j);
s += FString::FromInt(i);
UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(FName(*s));
m_mesh.Add(SphereVisual);
//SphereVisual->AttachTo(RootComponent, FName(*s), EAttachLocation::KeepRelativeOffset);
static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube"));
if (SphereVisualAsset.Succeeded())
{
SphereVisual->SetStaticMesh(SphereVisualAsset.Object);
SphereVisual->SetWorldLocation(FVector(i * 100, j * 100, 0.0f));
}
}
}
It crash on launch, but if I set the with and the height to 11, it does not crash. Maybe it works only by chance, if so, what is the good usage to add severals cube mesh ?
Thank you for your help, just starting ue4 and got a looooot of crash so far its annoying.