How to place a prefab on a mesh vertex

I must be doing something stupid here. I try to instantiate a prefab on the vertex of a mesh. The height (y) looks correct, but the x and z are limited to a very narrow range, so I get a cloud of objects floating in the air and under the (highly sloped) ground.

    MeshFilter meshFilter;
    GameObject prefab;
    Instantiate(prefab, meshFilter.mesh.vertices[10], Quaternion.identity, meshFilter.transform);

I also tried instantiating the object globally and then setting the parent, in case the coordinates weren’t being transformed. The effect was the same.

You probably need to account for the scale of the instantiated prefab in the scene.

The scale of both the prefab and the mesh is (1,1,1).

The vertices are in the local space of the mesh. To get from that to world space, use the meshfilter’s transform’s TransformPoint method.

1 Like

That worked. Thanks! No more floating bushes!