- Home /
How can I check if a GameObject has a Mesh?
I have a level editor in which I want to add a highlight effect to the object actively being modified.
All editable objects have '2D' models, so to do this I'm going to create a clone of the active object that is slightly larger with a different material applied to create a fake glow effect.
I'm not quite sure how to check if a GameObject has a mesh attached - I've been trying to use activeObject.GetComponent, but I can't compare that to bool/null so I can't guarantee I've found the right object. Some objects have Empty parents used for rotation, some don't, some have multiple children attached, etc - I need to be able to check if the way to get said Mesh has actually found it or not so I can ensure I get the correct object from the hierarchy.
Answer by dannyskim · Oct 08, 2012 at 11:27 PM
if( gameObject.GetComponent<MeshFilter>().mesh != null )
Debug.Log( name + " : Yes, I have a mesh! );
else
Debug.Log( name + " : Nope /wrist" );
Your answer
Follow this Question
Related Questions
Filling area under positions with Mesh 0 Answers
Find right mesh for collider 1 Answer
Generated Mesh Triangles not Being Made/Visible? 1 Answer
Why is my script constructed mesh rotating the wrong way 0 Answers
mesh deformation 1 Answer