Getting a mesh without manually assigning it.

Afternoon all,

For a while now we’ve been building all of our games using a Quad function that essentially generates a negative z facing quad. Works great. only problem is that this method doesn’t store the Mesh on the object… sooo… when it comes to making a prefab we have to manually assign that mesh or create a plane and put it behind the button, delete the renderer off the button etc etc.

I was toying around w/the idea of bringing in a quad from a 3D package that is scaled 1x1x1 (which is ho0w big we make the default quad) and assign the mesh from that object as the mesh for all my scene objects. So far it works and works well, now i can make prefabs outta things. yeah! :slight_smile:

MY question is, is there anyway i can manually FIND a mesh or meshFilter or object in the project (not in the heirerachy) based on a given name and assign that objects meshFilter to whatever i have selected? I can’t seem to find anything on finding MeshFilters or meshes etc. I can do it via a popup window, manually pick your mesh and hit go but i wanna make it a little more transparent.

Any help would be greatly appreciated!
Cheers
Bryan

I don’t know of a way to search through the project like that, but couldn’t you put all the mesh objects into an array and access them that way?

@Timbecile,

yeah thats possible. I actually found a bit of a shortcut way of doing it…

		GameObject findMrQuad = (GameObject)Resources.LoadAssetAtPath("Assets/Models/Quad.obj", typeof(GameObject));
		Quad.CreateQuadNegZ();
		GameObject currentObject = GameObject.Find("Quad");
		MeshFilter currentMeshFilter = currentObject.GetComponent<MeshFilter>();
		MeshFilter destMeshFilter = findMrQuad.GetComponent<MeshFilter>();
		GameObject newQuad = (GameObject)GameObject.Instantiate(findMrQuad);
		GameObject newFilterObj = GameObject.Find("default");
		MeshFilter newFilter = newFilterObj.GetComponent<MeshFilter>();
		currentMeshFilter.sharedMesh = newFilter.sharedMesh;
		DestroyImmediate(newQuad);

it works. i have no idea if thats a good/bad way of doing it but i figured since it was an editor only script its efficiency didn’t really matter. :slight_smile: