Mesh.vertices...why?

This is very basic, but I have a hard time understanding being a C++ developer by trade.

Given the following code (apart from it’s uselessness in general)

void Start () {
MeshFilter temp;
temp = GetComponent(typeof(MeshFilter)) as MeshFilter;
Mesh themesh = temp.mesh;
Debug.Log("Verts : "+themesh.vertices.Length);
Vector3[ ] verts = themesh.vertices;
for (int i=0;i<24;i++)
verts*.z = 10;*

  • themesh.vertices= verts;*
    // for (int i=0;i<24;i++)
    // themesh.vertices*.z = 10;*
    * }*
    Why do the commented out lines not work, whereas the assignment of the whole array does?
    It must be some C# thing I don’t know about?
    Is it because mesh.vertices returns a copy, but does implement an equals operator?
    Any hints appreciated :o)
    Kaj

blabla.vertices is a property. you can not assign something on a property.

What you need to do is assign the vertices array to a corresponding array, alter it then and assign the final array back to blabla.vertices as you did above

I assume you mean I can not assign to the elements of a property then? Because obviously when I assign the array I assign to a property.

I understand that when I assign a single vertex I assign to a local copy of the vertices…I guess I don’t understand why vertices returns a copy, whereas the mesh is an actual reference - I woulda expected that to be a copy as well then.

Kaj