- Home /
Mesh not being generated at all [Solved]
I have been working in Unity 2D and this problem is giving me the biggest headache. My code is as follows:
Mesh m_mesh;
void Start () {
m_mesh = new Mesh();
GetComponentInChildren<MeshFilter>().mesh
= m_mesh;
m_mesh.vertices = new Vector3[] { transform.position, new Vector3(1, 1, 0), new Vector3(1, -1, 0) };
m_mesh.uv = new Vector2[] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1) };
m_mesh.triangles = new int[] { 0, 2, 1 }; }
This script is on an Empty GameObject with an empty child GameObject that has both a MeshRenderer and MeshFilter on it. It is not a render issue or a normal issue because when I start play mode, a Mesh does get put into the MeshFilter on the child, but it is a completely blank mesh. There are no vertices and no triangles in it whatsoever.
The code is as simple as I have been able to reduce it to, and I still cannot see what is wrong. The mesh just simply seems to not be generating. Any help would be much appreciated.
Answer by M3L6H · Jul 30, 2017 at 09:18 PM
I am such an idiot. I figured it out. Apparently I had written a half-finished script ages ago, attached to some bizarre object in my hierarchy, and it was performing a FindObjectOfType<MeshFilter>()
and overwriting the mesh. Can't believe I overlooked that.
Your answer
Follow this Question
Related Questions
Draw/generate shape as 2D sprite? 0 Answers
Adding Verticies to Mesh 1 Answer
Create 3D mesh from PNG 0 Answers
There is a generation lag 1 Answer
Using rect.contains to check if gameobject is inside in worldspace 1 Answer