Search Unity

Vector3 Array - Can not be modified?

Discussion in 'Scripting' started by DubStepMaster, Nov 19, 2014.

  1. DubStepMaster

    DubStepMaster

    Joined:
    Jul 17, 2012
    Posts:
    40
    Hey there

    I made a script for changing a mesh in realtime and it worked.
    The problem is, that this script was not efficient enough and had to be modified.

    this is the script:

    Code (CSharp):
    1. mesh.vertices[triangles[hit.triangleIndex * 3 + 0]]=new Vector3(0.0f, 0.0f, 0.0f);
    but this line does not work.

    Instead of this line I had a new array of vertices, but my object is around 14.000 vertices. So two arrays of this size like:

    Code (CSharp):
    1. mesh.vertices = tempVerticies;
    It worked, but is not good at all.

    So my question:

    How I can change only one object in a Vector3 array?


    Thanks a lot for help


    Dub
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can't do that; you must get all the vertices, change one, then upload the vertices again. You can just do the "get all vertices" step once and keep the array around if you're going to be modifying the vertices frequently. The vertices exist on the GPU so it's not as simple as changing an entry in an ordinary array.

    --Eric
     
    DubStepMaster likes this.
  3. DubStepMaster

    DubStepMaster

    Joined:
    Jul 17, 2012
    Posts:
    40
    Thanks for the reply

    is there no other way to update a meshs vertices?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Nope.

    --Eric