Follow

Why is the TerrainData.SetHeight so slow?

Symptoms

  • I want to make our terrain tools run at an interactive speed.

Cause

You have implemented some in-house terrain forming tools, but applying any changes to a terrain results in a dramatic drop in performance making them barely usable.

Resolution

When creating you own terrain editing tools, TerrainData.SetHeights is naturally slower. This is because it needs to recalculate all the terrain LOD information, which is done on every call to SetHeights.

A patch was released for 5.2.0a3 where the SetHeightsDelayedLOD API was introduced to improve the speed at which TerrainData.SetHeights recalculates the LOD information.

In this patch release, the Editor uses two internal functions:

  • SetHeightDelayedLOD()
  • ApplyDelayedHeightmapModification()

With SetHeightDelayedLOD(), the LOD calculation can be skipped or delayed while editing, and is triggered once the mouse button is released.

In interactive editing scenarios, it is advised to call TerrainData.SetHeightsDelayLOD instead, followed by Terrain.ApplyDelayedHeightmapModification when the user completes an editing action.

More Information

For more information on TerrainData.SetHeights see this document here.

Go here to download the relevant patch where this SetHeightsDelayedLOD API has been implemented.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.