Crash when adding mesh

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.

Have you tried putting something in between the object names j and i ? so

FString s = FString::FromInt(j);
s += ".";
s += FString::FromInt(i);

You might be getting some repeating values without it.

Hello Nalyah,

I’d recommend looking into TTaM’s solution below, but if that does not work for you, I have a few questions:

  • Can you please provide your crash logs located in your project’s Saved->Logs folder?
  • Could you please provide your machine ID located in the Crash Reporter window that appears upon crashing, and ensure that you hit Send on the Crash Reporter window?

Thank you.

Well done! it works. A message instead of a crash would have helped me :stuck_out_tongue_winking_eye: