Search Unity

[GC/GetHeights()] Too large amount of garbage collected from GetHeights()

Discussion in 'Editor & General Support' started by crysicle, Mar 14, 2019.

  1. crysicle

    crysicle

    Joined:
    Oct 24, 2018
    Posts:
    95
    Hello, i'm making runtime terraformations by getting data of heightmaps with GetHeights() and setting data with SetHeightsDelayLOD(). As i didn't know about the profiler for over a week after starting this terraformation system i didn't realise that the only method of getting heightmap data from terrain would be causing a massive performance hit. Currently on the biggest heightmap selection area: 50x50 i'm getting 9.8kb GC per frame. While on 20x20, 1.6kb. This system is made to support multiple terraformations of many kinds happening at the same time to intersect between other terraformations smoothly. Because of this, many calls of GetHeights() are required each frame to sync data properly. I could make the system run less frequently, however, that would defeat it's purpose.

    I was wondering if anyone knows of another way of getting heightmaps besides the GetHeights() method or if there's a way to avoid really high GC by the GetHeights(). Currently my thoughts are to use GetHeights() at the beginning of the game to get all heightmaps from the whole terrain and come up with a way to sync them by retrieving and updating the same heights across multiple terraformations before updating a selected area to SetHeightsDelayLOD(). Though that would take quite a bit of effort to figure out how and i'm also not sure if that wont just create more performance issues. Thanks for any advice.

    Here's a video of some wave ring effects:


    Picture of the GC from the same wave ring effect: