- Home /
Triangles Index always zero - Custom Editor
In short, i have a custom editor script. I am trying to get the triangle index by clicking on a triangle. However, no matter what triangle on click on, the triangle index is always zero. The hit point does change as expected. Here is the portion of code i am using for the raycast which is contained within OnSceneGUI().
var ray = HandleUtility.GUIPointToWorldRay(e.mousePosition);
var hit = new RaycastHit();
if (Physics.Raycast(ray, out hit))
{
Debug.Log("Triange Index: " + (hit.triangleIndex * 3) + " Hit Point: " + hit.point);
}
Are you using a meshcollider? Sorry if this sounds obvious, but I want to at least get the easy ones out of the way.
I sorta feel dumb now.. I didnt even think about the actual collider. Thanks. Post as answer and ill accept
Answer by syclamoth · Sep 23, 2013 at 04:46 AM
From the Unity Scripting Reference:
Triangle index is only valid if the collider that was hit is a MeshCollider.
Just use a mesh collider instead.
$$anonymous$$akes perfect sense, thanks! Coded w.o looking at the reference (tisk tisk)