Hi,
i have been having some problems with regards to accesing my mesh in editor mode.
Every time i try
GetComponent<MeshFilter / SkindMeshRenderer>().SharedMesh/Mesh;
I get null. when i just try to get the component it also returns null.
I instantiate my object in editor mode first
(GameObject)UnityEngine.Object.Instantiate(gameObject);
And the debugger claims it exists so i dont know why its not working.
I also tried
GetComponentInChildren<>();
Weird
this script adds menu ‘UnityAnswers/GetAndAnalizeMesh’ and debugs verts and tris count. works fine in editor. works with project view and scene view.
GetAndAnalizeMesh.cs
using UnityEngine;
using UnityEditor;
using System.Collections;
public class MeshAnaliser : MonoBehaviour
{
[MenuItem("UnityAnswers/GetAndAnalizeMesh")]
static void GetAndAnalizeMesh()
{
GameObject go = Selection.activeGameObject;
if (go)
{
MeshFilter mf = go.GetComponent();
if (mf)
{
Mesh m = mf.sharedMesh;
if (!m) { m = mf.mesh; }
if (m)
{
Debug.Log(string.Format("vert:{0} tris:{1}", m.vertexCount, m.triangles.Length / 3));
}
}
}
}
}
Thanks man. I realized i could not edit meshes of no instantiated objects so i had to create them put them in a separate layer and hid flags for what i wanted. Thanks anyway
Hey thanks man. I just realized you had to instantiate the objects to have access to all that. So i had to create and hide it off screen. Thanks for the reply.