# Procedurally generating a mesh?

So i wrote the script for my new infinite terrain generator, but when i run it nothing happens, Working with meshes is kinda new to me so i was wondering if somebody a bit more experienced could take a peek and hopefully find my mistake.

``````using UnityEngine;
using System.Collections;

public class WorldGenesis : MonoBehaviour
{
void Start()
{
SectorInitialization(0,0,50,50);;
}

/*
//Will be used later when the inharitence from monoBehaviour is removed, this class will be called from another script.

public WorldGenesis(float originX, float originZ, int segmentsX, int segmentsZ)
{
SectorInitialization(originX,originZ,segmentsX,segmentsZ);
}
*/

public void SectorInitialization(float originX, float originZ, int segmentsX, int segmentsZ)
{
int _ArraySize = segmentsX * segmentsZ * 6;

Vector3[] _Vertices = new Vector3[_ArraySize];
int[] _Triangles = new int[_ArraySize];

int _Index = 0;
//Initialize Sector Vertices
for (float z = 0.0f; z < segmentsZ; z++)
{
for (float x = 0.0f; x < segmentsX; x++)
{
//First Triangle
_Vertices[_Index] = new Vector3(originX + x, 0.0f, originZ + z);
_Vertices[_Index+1] = new Vector3(originX + x, 0.0f,(originZ + z) + 1);
_Vertices[_Index+2] = new Vector3((originX + x) + 1, 0.0f, originZ + z);
//Second Triangle
_Vertices[_Index+3] = new Vector3(originX + x, 0.0f,(originZ + z) + 1);
_Vertices[_Index+4] = new Vector3((originX + x) + 1,(originZ + z) + 1);
_Vertices[_Index+5] = new Vector3((originX + x) + 1, 0.0f, originZ + z);
//Set Index for next batch of triangles
_Index += 6;
}
}

//Initialize Sector Triangles
//Initialize Sector Vertices
for (int v = 0; v < _Vertices.Length; v++)
{
_Triangles[v] = v;
}

//Generate Mesh
SectorGeneration(_Vertices, _Triangles);
}

public void SectorGeneration(Vector3[] vertices, int[] triangles)
{
GameObject _Sector = new GameObject();
_Sector.name = "Sector";

Mesh _Mesh = new Mesh();

_Mesh.vertices = vertices;
_Mesh.triangles = triangles;
_Mesh.RecalculateBounds();
_Mesh.RecalculateNormals();
_Mesh.Optimize();
}

}
``````

~Malarkey

You aren’t setting meshFilter.mesh = _Mesh.