Instancing a prefab at each point on a mesh

Hi there,

Just having a bit of trouble with this, I wanted to instance a prefab at each point of this mesh but I think I’m getting mixed up between points and verts…

I was looking at this mesh as a test

With this script I get 7 points but I would have thought there’d be 5-

            //Find all verts in mesh
            Mesh mesh = TargetMesh.GetComponent<MeshFilter>().sharedMesh;
            Vector3[] vertices = mesh.vertices;
            Vector3[] normals = mesh.normals;
            MeshCount = vertices.Length;

            //Move the helper to the current vert
            CurrentPoint = Mathf.Clamp (CurrentPoint, 0, vertices.Length - 1);
            PointHelper.position = vertices[CurrentPoint];

So if I instance at each of those verts I’ll get some objects at the same location.
Is there a way to get point position rather than verts maybe? Is that what I’m getting mixed up with?

Thanks!
Pete

You’re doing it correctly but unfortunately you can get duplicate vertices in a mesh - any vertex that doesn’t share the same colour/uv/normal will end up being assigned a new vertex slot in the list. You’d have to go through the vertices first and just find the unique ones.

Ahhh interesting, thanks for that. I ran a check for duplicates and that seemed to work. I am exporting the mesh out of Houdini and you have a fair amount of control of verts and points so I might be able to fix the outgoing stuff there if it comes to it.

Thanks!
Pete