Why would my custom generated cube mesh render from the inside?

Borrowing the GameGeneratedActor class found at the custom mesh generation wiki A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

I was able to render a cube utilizing code below. I leverage the custommeshcomponent plug in from within a blueprint, and link the below class to it.

However, what gets rendered is an inside the box view of the cube from every perspective. Whereas I am interested in rendering the outside of the cube. Does anyone have some insight regarding why I am getting this effect? Is it the order I am adding the triangles to the array? Or do I have to include some code that addresses the “normals” of the cube? Thanks!

AGameGeneratedMesh::AGameGeneratedMesh(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

	TSubobjectPtr<UCustomMeshComponent> mesh = PCIP.CreateDefaultSubobject<UCustomMeshComponent>(this, TEXT("GeneratedMesh"));

	float x = 0.0;
	float y = 0.0;
	float z = 0.0;

	TArray<FCustomMeshTriangle> triangles;
	FCustomMeshTriangle triangle;


	// CubeTop 	
	triangle.Vertex0 = FVector(x, y, z + 1);
	triangle.Vertex1 = FVector(x + 1, y, z + 1);
	triangle.Vertex2 = FVector(x + 1, y, z);
	triangles.Add(triangle);

	triangle.Vertex0 = FVector(x + 1, y, z);
	triangle.Vertex1 = FVector(x, y, z);
	triangle.Vertex2 = FVector(x, y, z + 1);
	triangles.Add(triangle);


	// CubeNorth
	triangle.Vertex0 = FVector(x + 1, y - 1, z + 1);
	triangle.Vertex1 = FVector(x + 1, y, z + 1);
	triangle.Vertex2 = FVector(x, y, z + 1);
	triangles.Add(triangle);

	triangle.Vertex0 = FVector(x, y, z + 1);
	triangle.Vertex1 = FVector(x, y - 1, z + 1);
	triangle.Vertex2 = FVector(x + 1, y - 1, z + 1);
	triangles.Add(triangle);

	//CubeEast
	triangle.Vertex0 = FVector(x + 1, y - 1, z);
	triangle.Vertex1 = FVector(x + 1, y, z);
	triangle.Vertex2 = FVector(x + 1, y, z + 1);
	triangles.Add(triangle);

	triangle.Vertex0 = FVector(x + 1, y, z + 1);
	triangle.Vertex1 = FVector(x + 1, y - 1, z + 1);
	triangle.Vertex2 = FVector(x + 1, y - 1, z);
	triangles.Add(triangle);

	//CubeSouth
	triangle.Vertex0 = FVector(x, y - 1, z);
	triangle.Vertex1 = FVector(x, y, z);
	triangle.Vertex2 = FVector(x + 1, y, z);
	triangles.Add(triangle);

	triangle.Vertex0 = FVector(x + 1, y, z);
	triangle.Vertex1 = FVector(x + 1, y - 1, z);
	triangle.Vertex2 = FVector(x, y - 1, z);
	triangles.Add(triangle);

	//CubeWest
	triangle.Vertex0 = FVector(x, y - 1, z + 1);
	triangle.Vertex1 = FVector(x, y, z + 1);
	triangle.Vertex2 = FVector(x, y, z);
	triangles.Add(triangle);

	triangle.Vertex0 = FVector(x, y, z);
	triangle.Vertex1 = FVector(x, y - 1, z);
	triangle.Vertex2 = FVector(x, y - 1, z + 1);
	triangles.Add(triangle);

	//CubeBot
	triangle.Vertex0 = FVector(x, y - 1, z);
	triangle.Vertex1 = FVector(x + 1, y - 1, z);
	triangle.Vertex2 = FVector(x + 1, y - 1, z + 1);
	triangles.Add(triangle);

	triangle.Vertex0 = FVector(x + 1, y - 1, z + 1);
	triangle.Vertex1 = FVector(x, y - 1, z + 1);
	triangle.Vertex2 = FVector(x, y - 1, z);
	triangles.Add(triangle);

	mesh->SetCustomMeshTriangles(triangles);

	RootComponent = mesh;
}

The issue you are experiencing is that your normals are pointing through the inside rather the outside. This is due to the way you add your vertexes to the mesh, invert the order (clock wise vs countet clock wise) and the normals will point to the outside.

In the case you want both sides and render the cube well from the inside amd the outside just ckeck the ‘double sided’ flag of the material.

Cheers,
Moss