How would I make an instantiated object appear at exact level of my terrain

How can I make sure instantiated objects are always going to be placed at the height of my terrain

Although my game is 3D the placement of objects/prefabs takes place in a top down view almost exactly the way its done in RTS games. (The object will be placed according to where the mouse is clicked)

Two methods come to mind

  • Raycast down from a suitable height above the terrain
  • Read the height from a height map

For most applications the raycasting will do fine. If you are after supreme commander like numbers of units, then explicitly reading from a height map will perform better.