- Home /
Detecting the subobject of a mesh
I have a mesh that has over a 3000 separate sub objects. (groups of polygons that dont touch the rest of the object)
As a single mesh, the mesh goes into the scene pretty fast. But the minute I break up each subobject into its own object, the game slows to a crawl.
Normally when you do a raycast, it detects the entire object that it hit. Is it possible to raycast so that it only returns the subobject that it hit?
That way I wouldnt need to break it apart.
Don't know if you can make this solve your problem, but the RaycastHit structure returns the triangle index for the triangle hit (RaycastHit.triangle). So if you can build a mapping between triangle and 'subobject', then it will work. I did this for hypertext links on one project, but my mesh was built at runtime making it easy to build the mapping. Assu$$anonymous$$g your shader does not need it, you might be able to encode your subobject references in a vertex attribute. You might be able to specify that in your 3D authoring program.
AS robertbu suggested I don't think you can see what is a submesh or not, you can either do as above suggested with triagle hit, or you can create different gameobjects with colliders and position them by hand. This if you are not instantiating the meshes at runtime, otherwise will be a pain in the ass.
Alternatively in the next unity update they are gonna add the ability to add multiple colliders per gameObject, you may want to look at that.
This has been asked and answered. I will try to find the thread