Search Unity

Resolved Weird lines at chunk borders

Discussion in 'Scripting' started by ethan123241, Feb 16, 2024.

  1. ethan123241

    ethan123241

    Joined:
    Sep 21, 2023
    Posts:
    5
    I am currently trying to generate terrain with a chunk system around the player using visual scripting. I have the system working fine (although quite slow) except on the chunk borders where there are clear lines running down them upload_2024-2-17_7-55-1.png
    to generate the chunks i get the unity plane, then offset each vertices' Y position by a random amount based on the Perlin noise function. i do this in 45 x 45 chunks then put all the vertices and triangles into a list, recalculate the normals and tangents, then set the mesh filter. this causes this lines for some reason. :/ here is my code: upload_2024-2-17_8-4-2.png
    If anyone knows how to fix either the slowness or the lines it would be greatly appreciated.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    As for the slowness, you're making the classic mistake of getting the mesh vertices inside your loop. Every time you do that, it creates a whole fresh copy of the mesh array and allocates it on the C# side. This is hugely wasteful. You should only get them once, and save the result array in a variable for reuse. I don't really know how to do that in Visual Scripting. This seems like much too complex a task to be performed with Visual Scripting to be perfectly honest. I recommend C# for better control and memory management.
     
  3. ethan123241

    ethan123241

    Joined:
    Sep 21, 2023
    Posts:
    5
    That does speed things up quite a bit however it is still slow. I'll see if i can figure out how to turn this into a C# script
     
  4. ethan123241

    ethan123241

    Joined:
    Sep 21, 2023
    Posts:
    5
    The lines at the chunk borders have been solved by a reddit user. it turns out the normals are not affected by the surrounding chunks