Can't Spawn Static Mesh Component

I am trying to spawn a grid but nothing happens.Not even a compile error.

// Fill out your copyright notice in the Description page of Project Settings.

#include "GridGenerator.h"
#include "Components/StaticMeshComponent.h"
#include "ConstructorHelpers.h"
// Sets default values
AGridGenerator::AGridGenerator()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = false;
	size = 16;
	sum = size * size;
	offsetAmount = 65;
	
	for (int i = 0; i < sum; i++) {
		if (sum % size == 0) {
			FVector temp;
			temp.X = sum+offsetAmount;
			temp.Y = offsetAmount;
			temp.Z = 0;
			offsetVector = offsetVector+temp;

			ReactiveFloor(worldLocation);

			MeshArray[i] = Mesh;

			offsetVector.X = offsetVector.X + offsetAmount;
		}
		else {
			ReactiveFloor(worldLocation);

			MeshArray[i] = Mesh;

			offsetVector.X = offsetVector.X + offsetAmount;
		}
	}
}

UStaticMeshComponent* AGridGenerator::SpawnMesh(FVector offsetVector)
{
	UStaticMeshComponent* Grid = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Grid"));
	Grid->SetupAttachment(RootComponent);

	static ConstructorHelpers::FObjectFinder<UStaticMesh>GridAsset(TEXT("/Game/Models-Textures/StaticMeshes/Plane_64x64.uasset"));

	Grid->SetStaticMesh(GridAsset.Object);
	Grid->SetRelativeLocation(offsetVector);
	Grid->SetWorldScale3D(FVector(1.f));
	worldLocation = offsetVector;
	return Grid;
}

void AGridGenerator::ReactiveFloor(FVector worldLocation) {
	FCollisionQueryParams RV_TraceParams = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, this);
	RV_TraceParams.bTraceComplex = true;
	RV_TraceParams.bTraceAsyncScene = true;
	RV_TraceParams.bReturnPhysicalMaterial = false;

	FHitResult RV_Hit(ForceInit);

	GetWorld()->LineTraceSingleByChannel(RV_Hit, worldLocation + (FVector(0, 0, 2000)), worldLocation - (FVector(0, 0, 2000)), ECC_EngineTraceChannel1);
	FVector temp2;
	temp2.X = worldLocation.X;
	temp2.Y = worldLocation.Y;
	temp2.Z = RV_Hit.ImpactPoint.Z;
	FRotator tempR;
	tempR.Pitch = (RV_Hit.ImpactNormal.X * 45);
	tempR.Roll = (RV_Hit.ImpactNormal.Y * 45);

	SetActorLocationAndRotation(temp2, tempR);
}

Hey,

Do you try to spawn meshes at runtime, because CreateDefaultSubObject and Construction helper works only at Construction Time (eg. when engine starting)?

Also maybe im wrong but as i see you’re not calling “SpawnMesh” function?
but anyway i think you try to spawn grid runtime so CreateDefaultSubObject and FConstruction helper wont work. Use NewObject and RegisterComponent instead.