Placing items on terrain in the editor

Hi, this has got to be an easy newbie question but I can't figure it out. I want to drag and drop entities from my Project into my scene, and have them show up on my terrain. But instead they show up some 100000000 miles away from the terrain object, and I have to manually pull them around for ten minutes until they sit on the terrain in the right spot. How do I get Unity to drop my stuff on the terrain? Or barring that, is there some way to say "put it where this other thing is"? I am having a really hard time positioning objects efficiently.

1 Like

If you drag objects into the hierarchy view, they will appear at 0,0,0. If you drag objects into the scene view, they appear some distance in front of the scene camera. You may therefore want to position the scene camera so that objects will appear in more convenient places. Also, if you hold down shift+command (shift+control on Windows) and drag the middle of the object, it will snap to the surface below.

using UnityEngine;
using UnityEditor;
using System.Collections;

public class AlignWithGround : MonoBehaviour {
    [MenuItem ("Tools/Transform Tools/Align with ground %t")]
    static void Align () {
        Transform [] transforms = Selection.transforms;
        foreach (Transform myTransform in transforms) {
            RaycastHit hit;
            if (Physics.Raycast (myTransform.position, -Vector3.up, out hit)) {
                Vector3 targetPosition = hit.point;
                if (myTransform.gameObject.GetComponent<MeshFilter>() != null) {
                    Bounds bounds = myTransform.gameObject.GetComponent<MeshFilter>().sharedMesh.bounds;
                    targetPosition.y += bounds.extents.y;
                }
                myTransform.position = targetPosition;
                Vector3 targetRotation = new Vector3 (hit.normal.x, myTransform.eulerAngles.y, hit.normal.z);
                myTransform.eulerAngles = targetRotation;
            }
        }
    }
}

An easy way to do this, is just to position your terrain at x=0, y=0, z=0. Then when you import a new object into your scene just type in the transform (position) box, 0 for each x, y and z co-ords. Tip: Once the object is placed at 0, 0, 0 press F, to quickly focus on it so you can move it around your terrain faster.