Here is my code, any help would be appreciated.
// Fill out your copyright notice in the Description page of Project Settings.
include “HorizontalWall.h”
// Sets default values
AHorizontalWall::AHorizontalWall()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
HorizontalWall = CreateDefaultSubobject<UProceduralMeshComponent>("HorizontalWall");
RootComponent = HorizontalWall;
}
void AHorizontalWall::CreateMesh()
{
// Define the size of your horizontal plane
float PlaneSize = 100.0f;
// Define the number of subdivisions for the plane
int32 NumSubdivisions = 10;
// Calculate the size of each subdivision
float SubdivisionSize = PlaneSize / NumSubdivisions;
// Initialize the vertices and UVs arrays
for (int32 Y = 0; Y <= NumSubdivisions; Y++)
{
for (int32 X = 0; X <= NumSubdivisions; X++)
{
FVector Vertex = FVector(X * SubdivisionSize - PlaneSize / 2, Y * SubdivisionSize - PlaneSize / 2, 0.0f);
Vertices.Add(Vertex);
FVector2D UV = FVector2D(static_cast<float>(X) / NumSubdivisions, static_cast<float>(Y) / NumSubdivisions);
UVs.Add(UV);
}
}
// Create triangles to form the mesh
for (int32 Y = 0; Y < NumSubdivisions; Y++)
{
for (int32 X = 0; X < NumSubdivisions; X++)
{
int32 VertexIndex = X + Y * (NumSubdivisions + 1);
// Triangle 1
Triangles.Add(VertexIndex);
Triangles.Add(VertexIndex + 1);
Triangles.Add(VertexIndex + NumSubdivisions + 1);
// Triangle 2
Triangles.Add(VertexIndex + NumSubdivisions + 1);
Triangles.Add(VertexIndex + 1);
Triangles.Add(VertexIndex + NumSubdivisions + 2);
}
}
// Create the mesh section
HorizontalWall->CreateMeshSection(0, Vertices, Triangles, TArray<FVector>(), UVs, TArray<FColor>(), TArray<FProcMeshTangent>(), true);
if (Material)
{
HorizontalWall->SetMaterial(0, Material);
}
}
// Called when the game starts or when spawned
void AHorizontalWall::BeginPlay()
{
Super::BeginPlay();
CreateMesh();
}
void AHorizontalWall:: Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}