Unity to Godot: MeshFilter

Godot Version

4.1.1

Question

I’m working on porting a unity project that I made a while ago over to Godot.

In Unity I have a class that looks like this:

public class MeshGenerator 
{

	public SquareGrid squareGrid;
	public MeshFilter walls;

	void CreateWallMesh(int[,] map, float squareSize, int tileAmount){
		MeshCollider currentColliders = walls.gameObject.GetComponent<MeshCollider>();
		Destroy(currentColliders);
		CalculateMeshOutlines();

		List<Vector3> wallVertices = new List<Vector3>();
		List<int> wallTriangles = new List<int>();
		Mesh wallMesh = new Mesh();
		float wallHeight = 5;

		foreach(List<int> outline in outlines){
			for(int i = 0; i < outline.Count-1; i++){
				int startIndex = wallVertices.Count;
				wallVertices.Add(vertices[outline[i]]); // left vertex
				wallVertices.Add(vertices[outline[i+1]]); // right vertex
				wallVertices.Add(vertices[outline[i]] - Vector3.up * wallHeight); // bottom left vertex
				wallVertices.Add(vertices[outline[i+1]] - Vector3.up * wallHeight); // bottom right vertex

				wallTriangles.Add(startIndex + 0);
				wallTriangles.Add(startIndex + 2);
				wallTriangles.Add(startIndex + 3);

				wallTriangles.Add(startIndex + 3);
				wallTriangles.Add(startIndex + 1);
				wallTriangles.Add(startIndex + 0);
			}
		}
		wallMesh.vertices = wallVertices.ToArray();
		wallMesh.triangles = wallTriangles.ToArray();

		MeshCollider wallCollider = walls.gameObject.AddComponent<MeshCollider>();
		wallCollider.sharedMesh = wallMesh;

		float textureScale = walls.gameObject.GetComponentInChildren<MeshRenderer> ().material.mainTextureScale.x;
		float increment = (textureScale / map.GetLength(0));
		Vector2[] uvs = new Vector2[wallMesh.vertices.Length];
		float[] uvEntries = new float[]{0.5f,increment}; 

		for (int i = 0; i < wallMesh.vertices.Length; i++) 
		{
			float percentY = Mathf.InverseLerp ((-wallHeight) * squareSize, 0, wallMesh.vertices [i].y) * tileAmount * (wallHeight / map.GetLength(0));
			uvs [i] = new Vector2(uvEntries[i % 2],percentY);
		}

		wallMesh.uv = uvs;
		wallCollider.sharedMesh = wallMesh;
		walls.mesh = wallMesh;
	}

And I’m getting an error that says

The type or namespace name ‘MeshFilter’ could not be found (are you
missing a using directive or an assembly reference?)

I’m curious what the correct way to do it in Godot is.

Hey @andyd273 hope you Allright.
In Godot, the equivalent to Unity’s MeshFilter is working with the ArrayMesh. The MeshDataTool is also a useful tool for calculating mesh data that isn’t available in ArrayMeshes.

Keep in mind that the MeshDataTool can only be used on meshes that use the PrimitiveType.MESH_PRIMITIVE_TRIANGLES1.

If you need to create a mesh that changes over time (such as growing grass), consider using ImmediateMesh in Godot 4.x
or ImmediateGeometry in Godot 3.x2.

Hope this helps! :blush: