Finding the nearest triangle to a point in space

How does one find the nearest triangle/face in a mesh to a certain point in space? Is there a built in function for that that would hopefully be more efficient than testing against the coordinates of all the faces of the mesh?

khalibloo you can use object.closest_point_on_mesh(point) or the mathutils.kdtree module, search in this forum or in manual…
in BGE I’m not so sure though

thanks very much. never mind BGE, this is exactly what i was looking for.