How can I get Z of my landscape at (X,Y)?

Hello,

So I have two questions:

Given a (X,Y) coordinates inside the bounds of a landscape, how can I get the Z position?

Also, I’m making a game where you can spawn buildings on a landscape.
Problem is, if the player spawn that building on a slope, the building will looks like its flying. (no rotations are applied to it). So is there any way to flatten the terrain at runtime?

Thank you!

I’ll go ahead and answer this even though it is quite dated, just do a line trace at the X, Y, and highest allowed Z point, to the X,Y, and lowest allowed Z point. The hit location will return the surface height as long as it is within lowest and highest point variables.