Hi I have a vanishing mesh: this short script works if I play it one time, the second time the mesh has 0 vertices and 0 triangles and I have to reload unity. The scene is composed by a camera, a directional light and a empty gameobject where I've attached this script. Can someone help me? Thanks Lka SaveVertexFaces.cs : Code (csharp): using UnityEngine; using System; using System.Collections; using System.Text; class SaveVertexFaces : MonoBehaviour { public string fileName; public GameObject meshExport; public void Start() { Save(meshExport); } private void Save(GameObject gobject) { Mesh meshP = ((MeshFilter)(gobject.GetComponent(typeof(MeshFilter)))).mesh; Debug.Log("vertices count: " + meshP.vertexCount.ToString()); int i; string s=string.Empty; for(i=0;i<meshP.vertexCount;i++) s+= "v " + meshP.vertices[i].x.ToString(LUtils.numberFormat) + " " + meshP.vertices[i].y.ToString(LUtils.numberFormat) + " " + meshP.vertices[i].z.ToString(LUtils.numberFormat) + '\n'; for(i=0;i<meshP.triangles.Length;i++) s+= "t " + meshP.triangles[i].ToString(LUtils.numberFormat) + '\n'; LUtils.WriteFile(fileName, s); } } LUtils.cs: Code (csharp): using System; using System.Collections; using System.Text; #if !LGWINDEBUG using UnityEngine; #endif class LUtils { public static string AbsPath(string filename) { #if LGWINDEBUG return System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, filename); #else return System.IO.Path.Combine(Application.dataPath, filename); #endif } static System.Globalization.NumberFormatInfo nfi; public static System.Globalization.NumberFormatInfo numberFormat { get { if (nfi == null) { nfi = new System.Globalization.NumberFormatInfo(); nfi.NumberDecimalSeparator = "."; nfi.NumberGroupSeparator = ","; } return nfi; } } public static void WriteFile(string filename, string text) { System.IO.FileStream fs; System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); byte[] ar = enc.GetBytes(text); fs = new System.IO.FileStream(filename, System.IO.FileMode.Create); try { fs.Write(ar, 0, ar.Length); } finally { fs.Close(); } } }
Instantiating the object all is working. Thanks Lka Code (csharp): public void Start() { Save(Instantiate(meshExport) as GameObject); }