Check for meshfilter

I’m trying to get the bounds of each mesh within an FBX file. Some of the elements don’t have a mesh. How do I check for the existence of a meshfilter without creating an error because there isn’t one?

	Mesh mesh = t.GetComponent<MeshFilter>().mesh;
	   if (mesh != null) 
		{
			Bounds bounds = mesh.bounds;
			location.Add(bounds.center);
		}

gives me the error “MissingComponentException: There is no ‘MeshFilter’ attached to the “3D View: Lights” game object, but a script is trying to access it.”

Thanks.

MeshFilter mF = (MeshFilter) t.GetComponent<MeshFilter>();

if(mF)
{
    if(mF.mesh)
    {
         // bounds stuff
    }
}
1 Like

terrific, thanks!