Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Does Unity Redraws the whole mesh if u update 1 vertex?

Discussion in 'General Graphics' started by robertolodongo, Nov 24, 2023.

  1. robertolodongo

    robertolodongo

    Joined:
    Apr 19, 2022
    Posts:
    15
    Does Unity Redraws the whole mesh?

    //lets say i have a terrain with many triangles

    Vector3[] vertices new Vector3[] {new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 0)};
    vector2[] uv = new Vector2[] {new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1)};
    int[]triangles = new int[] {0, 1, 2};

    mesh.vertices = vertices;
    mesh.uv = uv;
    mesh.triangles = triangles

    //Now i set 1 previous vertex

    vertices[0].Set[1,3,6]
    mesh.vertices = vertices;

    Im passing the vertices array again, so does this means the whole array of vertices is passed to mesh.vertices and therefore all the triangles are redrawn, or it only redraws the modification i did when i setted the vertex 0?
    And if thats the case, Is there a way to only modify 1 vertex without redrawing the whole mesh?
     
    Last edited: Nov 24, 2023
  2. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    941
    I'm not quite clear on what you are asking so I'll try to clarify as best I can: Terrains and indeed all graphics are drawn every frame regardless of any changes that may have occurred to the mesh data. As well, all rendering is deferred until a specific point during the update cycle (unless you're manually forcing something to render immediately) so regardless of the number of changes made to a mesh in a single update it will still only render once per frame. So either way you don't need to worry about it that much.
     
  3. robertolodongo

    robertolodongo

    Joined:
    Apr 19, 2022
    Posts:
    15
    Im sorry i didnt explain myself properly, lets say a game like minecraft, removing and adding blocks, in this case, i would have to redrawn/update a whole chunk instead of just 1 cube, so if i have a 32 by 32 chunk and i add, or remove a cube, with the previous logic would i be updating the whole chunk, with the new vertices array information i passed to mesh.vertices?

    Thanks for your answer it did help me with my initial doubt.
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,864
    This depends on the setup.
    Normally you'd need to update the whole mesh if you just set the vertices.
    You can do it with better performance using the MeshData API, where you can get a pointer to the mesh data and write to that
     
  5. robertolodongo

    robertolodongo

    Joined:
    Apr 19, 2022
    Posts:
    15
    Yea my doubt originated from those two scenarios
    1 update the whole mesh
    2 update a part of it
    thats more or less what im trying to figure out but it seems that updating the whole mesh is the correct way of thinking about it (?)
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,864
    Most likely yes