How does terrain.SampleHeight() work?

Say I want to randomly place a bunch of instances(let’s say stop signs) across my terrain at runtime. My terrain was generated at runtime as well.

So I figure something like this would work:

Vector3 signPosition = new Vector3(xVal, myTerrain.SampleHeight(???), zVal);

gameObject = Instantiate(Resources.Load(“prefabs/StopSign”), signPosition, Quaternion.identity) as GameObject;

Problem is, I have no idea what to put in for those question marks. Could someone please explain what info needs to go in there so that the Y position is the sampleHeight of the terrain position I crave? I would have thought it would have just been an x value and a z value but that dog won’t hunt.

I will rephrase and elaborate on this question if it helps, JUST DON’T TELL ME TO GOOGLE IT MANG.

SampleHeight expects that you pass a world position: it apparently ignores the Y coordinate and returns the height of that position relative to the terrain origin. In practical terms, you can find the signPosition with this code:

...
// make Vector3 with global coordinates xVal and zVal (Y doesn't matter):
Vector3 signPosition = new Vector3(xVal, 0, zVal);
// set the Y coordinate according to terrain Y at that point:
signPosition.y = Terrain.activeTerrain.SampleHeight(signPosition) + Terrain.activeTerrain.GetPosition().y; 
// you probably want to create the object a little above the terrain:
signPosition.y += 0.5f; // move position 0.5 above the terrain
GameObject sign = Instantiate(Resources.Load("prefabs/StopSign"), signPosition, Quaternion.identity) as GameObject;
...