- Home /
Hi, It is possible to get all the attributes inside a mesh with an script
Hi, i have a project in unity in which i imported a 3D model, the same comes with some basic information of every component of the model.. in unity avery object has a mesh and all the attributes are stored inside that mesh.
the question is it is possible get the meshed of an object and store and then retrieve these attributes?
i currently have this code, looks logical for me but i'm lost in the last step, idk if this is even possible.
public MeshFilter canmesh;
public GameObject can;
void Start()
{
//if (can == null)
can = GameObject.FindWithTag("can");
canmesh = can.GetComponent<MeshFilter>();
Debug.Log("CAN MESH", canmesh);
}
find attached a picture of the mesh attributes in UI
im trying to get locate the object - get inside the filter mesh and then print it, lol
any help?
Thanks,
Answer by Bunny83 · May 16, 2016 at 09:46 PM
Your question is very confusing as it's not clear what you mean by attributes and where they are actually stored. If you just talk about the file name / name of the mesh of the imported model you can do:
MeshFilter mf = can.GetComponent<MeshFilter>();
Mesh mesh = mf.sharedMesh;
Debug.Log("MeshName: " + mesh.name);
If you talk about other attributes, you should be more clear what you mean and where they are stored / defined.
basically what i want to do is get this attributes as strings
please refer to the image bellow.
Hi @Bunny83 thanks for your answer, i have a 3d model imported into unity, each of the objects of the model has its own set of attributes which some of them are getting into the mesh when imported to unity, refer to the image, there name of an object and ID inside the mesh... what i want to know is can i get those attributes with code?
Thanks.
Well, if you indeed talk about the name of the mesh, you can use what i posted in my answer above. The other things are not "attributes" but assigned materials. The materials don't belong to the $$anonymous$$esh or the $$anonymous$$eshFilter component, but the $$anonymous$$eshRenderer component which is responsible for rendering the $$anonymous$$esh.
To get the materials list you can do this:
$$anonymous$$eshRenderer renderer = GetComponent<$$anonymous$$eshRenderer>();
$$anonymous$$aterial[] mats = renderer.shared$$anonymous$$aterials;
foreach (var mat in mats)
{
Debug.Log("$$anonymous$$aterial name: " + mat.name);
}
If you need any more help you should be more precise for what you need that information.