I am using RaycastHit.triangleIndex to identify a location on a mesh (very low poly). However, I have discovered that a given triangle on the mesh does not have the same triangleIndex value from one execution of the game to the next (index "1" maps to location "A" on the first run, but location "B" on the second run). It is consistent within a given game, but for my mapping to work I need it to be consistent across games.

Given that I am using Raycast, how can I consistently identify the same logical location on the model?


  • The game object must be instantiated from a prefab (there are a variable number of them), so it could be that this is why the vertex order changes? Is there a way to instantiate with consistent vertex order?

  • If I need to ask the artist to recreate the asset with submeshes for each location, will I be able to consistently identify those?

  • \$\begingroup\$ Have you tried using hit.point instead? \$\endgroup\$
    – seahorse
    Commented Dec 4, 2014 at 12:32
  • \$\begingroup\$ " However, I have discovered that a given triangle on the mesh does not have the same triangleIndex value from one execution of the game to the next". Are you sure about this? It sounds weird and unexpected. \$\endgroup\$
    – Heisenbug
    Commented Dec 4, 2014 at 13:56
  • \$\begingroup\$ @Heisenbug I have found references to inconsistent triangle ordering when importing meshes, so maybe this is related? code examples seem to be about "apply force at the triangle you just found" rather than "use triangle/point as a lookup reference", so maybe it isn't a common use case? \$\endgroup\$ Commented Dec 4, 2014 at 14:19
  • \$\begingroup\$ @seahorse I am wanting to identify the location on the mesh not in space - e.g. "left side", "door", "arm", "ear" (where these are all parts of a single mesh) \$\endgroup\$ Commented Dec 4, 2014 at 14:25
  • \$\begingroup\$ I'm not sure I have to investigate, but I don't see any reason why order should be changed if the mesh is the same with the same import settings. Be aware that optimizing mesh data in import settings will of course modify the mesh. And in any case probably unity reorder polygons while importing mesh, so the order/number is different from the modeling program you have used. \$\endgroup\$
    – Heisenbug
    Commented Dec 4, 2014 at 14:35

2 Answers 2


My suggestion is make empty gameObjects on the certain points, add (sphere) colliders(isTrigger=true), and use hit.point to accomplish that same purpose.

This is less troublesome than having your artist to recreate sub-meshes.

I haven't use the trianglIndex before but according to the API: triangleIndex is accurate but it may be difficult to collect the indexes, and a set of arrays MUST be made to declare certain points on the mesh.


You might check to see if the triangles in each index variant are still listed in the same order (for instance, sometimes it's A0 B1 C2 D3, sometimes it's B0 C1 D2 A3, but always the same triangles come before and after each other in the index). If that's the case, you might be able to calibrate when you instantiate your gameobject by shooting a raycast at the triangle you want to treat as index 0 and noting the difference between 0 and its actual index. You could infer the index of other triangles from there.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .