I am trying to use vertex snapping in the scene GUI. I found this method in this documentation but I cannot get it to function properly. I input a GUI point, given by the example given in this GUI Point documentation, but the output Vector3 vertex seems very random to me.
This is the code I used to test this method
private void OnSceneGUI()
{
//Set sphere color
Handles.color = Color.red;
//Get the mouse position
Vector2 mousePos = Event.current.mousePosition;
//Convert it to a gui point
Vector2 guiPoint = GUIUtility.ScreenToGUIPoint(mousePos);
//Find the nearest vertex to that gui point
bool found = HandleUtility.FindNearestVertex(guiPoint, out Vector3 vertex);
//Draw a sphere on that vertex
Handles.SphereHandleCap(0, vertex, Quaternion.identity, HandleUtility.GetHandleSize(vertex) * .2f, EventType.Repaint);
//Log results
Debug.Log(found + ": " + vertex);
}
This is what it looked like in the Scene View
I expected the Sphere to snap to vertices close to the mouse cursor, but it does not do that.
Could someone maybe explain to me how to use this properly?
Thanks!