Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Adding polygons vs. Adding object speed

Discussion in 'Scripting' started by AustinLee, Jun 24, 2015.

  1. AustinLee

    AustinLee

    Joined:
    Dec 20, 2012
    Posts:
    2
    I am creating a terrain with level of detail changes which seamlessly interconnect between lower and higher level of details. There are two ways I can do this in the script.

    One method I could add and delete vertices and polygons on already existing mesh in realtime or I could add and delete plane objects which would have to their vertices tweaked after to fit a height map. Which method do you think would be faster? I don't know if adding and deleting vertices and polygons may have to redraw the entire mesh, whereas adding and deleting plane objects might be slower for Unity.

    Thanks,
    AustinLee
     
  2. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    I'm not sure, but I'd expect modifying the mesh to be faster than adding and removing objects as long as you're careful about how you do it.
     
    AustinLee likes this.
  3. Mr-Mud

    Mr-Mud

    Joined:
    Mar 8, 2015
    Posts:
    37
    Though I haven't used it myself, Unity supports something named LOD group (Level Of Detail). I assume this is something which you want to acchieve (though it is limited to Unity Pro, prior to Unity 5).

    Should you want to reinvent the wheel, there is a third option: en-/disable a GameObject. This has less overhead than destroying and recreating... things.

    As for editing meshes, it does have quite some overhead. First you have to retrieve the data, copying everything into memory. Then edit it, to finally writing everything back, essentially copying it again.
     
    AustinLee likes this.
  4. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    Mud, are you sure editing meshes works that way? I thought once you created the arrays and assigned the reference to the mesh, you were free to edit the vertices and so forth like any other array. Surely the mesh class isn't really copying the whole thing each time you change a vertex or something? Don't know for sure, maybe I'm wrong about this one.
     
    AustinLee likes this.
  5. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    Granted, AustinLee is talking about changing the number of verts and redoing a lot of the triangles. Maybe in that case it needs to be a new mesh after all like you said since the number of elements in the mesh array changes.

    Anyway, LOD is probably a better option anyway. Good thinking.
     
    AustinLee likes this.