How do I place the matching Vector3 array values of a Vector3 array in a new array ?

hello , I am attempting to place the values of an array that are the same; inside of a separate.

this is a code i adopted and tried to use to move an objects verts , however; this script assigned points called “handles” to each vert as a child of the object . As a result , moving the handles results in simply pulling the mesh apart by individual verts.

I tried to group all the verts with the same Vector3 positions into an array and setting all the vector3 values of that array to be equal to the position of the handle.

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]

public class VertHandler : MonoBehaviour
{
    Mesh mesh;
    Vector3[] verts;
    Vector3 vertPos;
    GameObject[] handles;
    void OnEnable()
    {
        mesh = GetComponent<MeshFilter>().mesh;
        verts = mesh.vertices;
        foreach (Vector3 vert in verts)
        {
            vertPos = transform.TransformPoint(vert);
            GameObject handle = new GameObject("handle");
            handle.transform.position = vertPos;
            handle.transform.parent = transform;
            handle.tag = "handle";
            //handle.AddComponent<Gizmo_Sphere>();
        }
    }

    void OnDisable()
    {
        GameObject[] handles = GameObject.FindGameObjectsWithTag("handle");
        foreach (GameObject handle in handles)
        {
            DestroyImmediate(handle);
        }
    }

    void Update()
    {
        handles = GameObject.FindGameObjectsWithTag("handle");
        for (int i = 0; i < verts.Length; i++)
        {
            verts _= handles*.transform.localPosition;*_

}
mesh.vertices = verts;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
}

Ok, for mesh manipulations you actually want to store the indices of similar vertices so you can update them all at once. just copying the vector3 value won’t help much since you don’t know where it belongs in the actual vertices array.

I would suggest to use a helper class like:

public class VertHandle
{
    public Vector3 pos;
    public List<int> indices = new List<int>();
    public Transform handle;
}

With that class you can create a unique handle for each vertex-group like this:

List<VertHandle> GenerateHandles(Vector3[] aVertices, float aThreshold)
{
    float sqrThreshold = aThreshold*aThreshold;
    List<VertHandle> result = new List<VertHandle>();
    for(int i = 0; i < aVertices.Length; i++)
    {
        VertHandle h = null;
        for(int n = 0; n < result.Count; n++)
        {
            if ((result[n].pos - aVertices*).sqrMagnitude < sqrThreshold)*

{
h = result[n];
break;
}
}
// if there’s no handle with that position yet, create one.
if(h == null)
{
h = new VertHandle() { pos = aVertices*};*
h.handle = new GameObject(“handle”).transform;
h.handle.parent = transform;
h.handle.localPosition = aVertices*;*
h.handle.tag = “handle”;
result.Add(h);
}
// add the current vertex to the indices list of that handle
h.indices.Add(i);
}
return result;
}
This gives you a list of handles. To apply the changes from the handles to your actual vertices, just use
void ApplyChanges(List aHandles, Vector3[] aVertices)
{
for(int i = 0; i < aHandles.Count; i++)
{
Vector3 pos = aHandles*.handle.localPosition;*
for(int n = 0; n < aHandles*.indices.Count; n++)*
{
aVertices[aHandles*.indices[n]] = pos;*
}
}
}
Keep in mind when destroying the handles to use
foreach (VertHandle h in handles)
{
DestroyImmediate(h.handle.gameObject);
}
Also make sure you store the handles List in your class in a member variable.