- Home /
Big FPS drop when using SetHeights on terrain
I'm using GetHeights and SetHeights to alter the terrain at run time. I only change 1 height at once, but i'm still getting a massive stutter when I use SetHeights.
I don't have any trees or grass on the terrain, it's purely terrain at this point.
My terrain is fairly large, so I assume it's because it's recalculating the collision mesh?
Is there any way of reducing the stutter or is this simply something I have to live with?
Answer by DGArtistsInc · Aug 23, 2011 at 01:36 AM
Go into Set Resolution which is under terrain and lower the the terrain width and length. This will cause the terrain to be smaller. This should help this problem. Or you could just make the graphic quality less so it will run faster.
This does help some, although it's difficult to know how small to make the terrain to compensate for weaker computers, and if it gets too small then the world is too small.
If I had multiple small terrains somehow stitched together, would this be faster? I assume it doesn't recalculate all terrain collisions if you have multiple terrains and you only change the heights of one?
If you had multiple smaller terrains, you'd have a hard time making sure the edges stayed aligned. As far as I can tell, SetHeights is recalculating the entire terrain mesh- so no, there isn't really a way to speed it up, unfortunately. Could you do some crazy LOD thing where the terrain gets more detailed if your computers are faster, or am I talking out of my bum about things I don't really understand?
Well, I'm only changing the height of 1 point per click, so I'd only need to alter more than 1 terrain if the player is editing a point along the very edge of a terrain, which is easy enough to detect.
Assu$$anonymous$$g all terrains are equal in size then I can simply tile them in a grid and basically make all ajoining edges share the same heights.
I could use a higher resolution for the terrain depending on the computer power but that would make balancing really hard. It would also mean I couldnt make it multiplayer (which I'm hoping to do).
Well from the looks of it, having multiple smaller terrains is the only practical solution here.
Answer by Ponasity · Mar 28, 2017 at 04:44 PM
The Unity docs say "The area affected is defined by the array dimensions and starts at xBase and yBase. The heights array is indexed as [y,x]." This means you can directly address the nodes you are altering without accessing any others. Simply use the first 2 values in the setHeights function as the starting point for the area you want to alter, and then the size of the array defines the ending point. I saved 40 FPS when I changed my code to this.
Your answer
Follow this Question
Related Questions
How to make lag free terrains 1 Answer
Large Colliders Hitting Terrain 0 Answers
3d model with lower poly count than another model causing tons of lag 0 Answers
Why _terrainData.SetHeights() resizes the terrain? 0 Answers
Low FPS any ideas ? 1 Answer