You are correct!
I rarely drag & drop stuff onto the scene view itself because, well, the position is NEVER what I want it to be anyway. I’m more inclined to drag it into the scene hierarchy where the object gets placed at the origin respectively what the prefab root transform indicates, then move it. But as worlds get larger then yes, you’d want to not drop the object, then pick it up again and move it in order to snap it.
Btw, I noticed if you have Grid snapping set to one value (say: 5) and Increment snapping to half of grid snapping (here: 2.5) this lets you quickly snap objects to the grid but when you need half-grid snapping you can just hold down Ctrl and drag, that’s kinda nice because I’ve fumbled with this in the past.
Anyway, I made a quick script that could certainly be improved (perhaps an editor script / EditorTool that checks the selected object(s) and determines whether grid snapping should be enabled and what the grid size will be based on info obtained from the object itself such as tags or a component).
This script goes on every prefab that MUST stay on a grid no matter what:
using UnityEngine;
[ExecuteAlways]
public class SnapToGridInEditor : MonoBehaviour
{
[SerializeField] private Vector3 m_GridSize = new(2.5f, 0f, 2.5f);
private void Awake()
{
#if UNITY_EDITOR
if (Application.isPlaying)
Destroy(this);
#else
Destroy(this);
#endif
}
private void Update()
{
#if UNITY_EDITOR
if (Application.isPlaying == false)
{
var pos = transform.position;
transform.position = new Vector3(
Mathf.RoundToInt(pos.x / m_GridSize.x) * m_GridSize.x,
Mathf.RoundToInt(pos.y / m_GridSize.y) * m_GridSize.y,
Mathf.RoundToInt(pos.z / m_GridSize.z) * m_GridSize.z);
}
#endif
}
}
When you drag in a prefab with this script on the prefab root, it will instantly snap to the given grid position. I left grid.y at 0 so in that case the object will only move on the XZ plane which is handy if you work with a flat terrain.
Note: I expected a division by zero exception in (pos.y / m_GridSize.y) but that doesn’t happen. No idea why.
The snapping persists even if grid snapping in the scene view is disabled. If you don’t want the object snapping, you’d have to disable the component.
The hack-ish thing about this is that it lives on the prefab itself and modifying the script settings shows up as prefab overrides, which they are. It also adds minimal overhead as the component gets destroyed when entering playmode.
Hence the recommendation to make this an EditorTool that is game-aware and knows that any object tagged “GridSnap” or has a component of type “SnapToGrid” (empty script, or at most providing grid settings) will require the object to be grid snapped.
This could be improved even further with a toogle to have “snap to ground” available, particularly useful with terrain, or generally snapping to meshes, colliders and their surface normals for alignment. I think some of that already exists with some key combo and certainly there are tools in the store that help out there.