- Home /
Editor Snap to floor?
Is there a hotkey like unreal to snap a gameobject in the scene to something below it like unreals end key? I know this somewhat partially exists because when you drag a prefab from the asset folder out into the viewport and continue to hold the mouse button down it will snap to what ever you are mousing over. But is there a key to do this when a object is already in the editor hierarchy?
I want it to work like it does when you drag a new asset out like this (but for existing assets in the editor). The vertex snapping is kind of too complex especially when its a high vertex model.
https://dl.dropboxusercontent.com/u/94084288/ShareX/2015/05/2015-05-29_00-47-54.mp4
Personally, with the advent of Pro tools like "Pro Grids", Unity's snapping re$$anonymous$$ds me of a famous Back to the future II quote :
Roads? Where we're going, we don't need roads.
Unity snapping has always been there, but grab Pro Grids and see the difference altogether, Unity bought it so we could use it for free and because it was better than anything currently available in the engine for object placement and snapping.
(Pro Grids ftw honestly) :)
Answer by blueriver123 · Oct 27, 2017 at 06:05 AM
try unity manual
Surface snapping
While dragging in the center using the Move tool, hold Shift and Control (Command on Mac) to quickly snap the GameObject to the intersection of any Collider.
This took me a second to sort out, but it works great! While holding shift+ctrl, you have to use the square in the center of the $$anonymous$$ove tool (which you said). I was initially trying to use the arrows of the move tool, which does not work.
TL;DR Be sure to use the center of the move tool, not the arrows.
I made a whole game and then realized this was a thing. Nice to know!
Answer by ninjapretzel · May 29, 2015 at 07:40 AM
There is 'vertex snapping' on the v-key when using the Translate or Rect tools.
Select the object you want to move.
Press V
Hover over the vertex you want to snap
Click and drag it to the vertex you want to move it to
Unity will move the object so the two vertices are touching.
(Edit: Who thought it was a good idea to have lines that are together merge?)
Is there also a key for doing it based off pivot or something, It can be kind of hard when its a high vertex mesh to get the bottom of something
I don't know, but when you drag a prefab from the project window onto a solid, it does place the object at the origin. The only thing is you can't do the same when the object already exists in the scene.
It's also possible to script something that makes the object move onto the ground- put the content of this pastebin in a script in a folder named "Editor". http://pastebin.com/2vrUVf5E
It will add a menu option in the top menu that you can use to move an object's pivot into the ground. If Unity doesn't provide a solution for something, it's pretty easy to extend the editor and add the feature with a little script like that.
Thanks for posting this! I improved this a tad to be more like Unreal.
Shortcut is now Shift+END and the script now looks in the select object for a $$anonymous$$eshRenderer (first one it finds as written) and it checks the renderer's bound.extents and compares the resulting position from the center to the extent with the selected objects y position. This ensures that if a transform has a pivot at the bottom of the object, the script doesn't blindly assume a center pivot.
Thank you for your help!
The last version of the script can be improved in order to also be able to snap objects in where the pivot point is outside of the mesh renderer boundaries, by replacing the foreach loop with the next code snippet:
foreach ( Transform t in Selection.transforms )
{
$$anonymous$$eshRenderer renderer = t.GetComponentInChildren<$$anonymous$$eshRenderer>();
if ( renderer != null )
{
RaycastHit rayhit;
if ( Physics.Raycast( renderer.bounds.center, Vector3.down, out rayhit ) )
{
float offsetY = rayhit.point.y - renderer.bounds.$$anonymous$$.y;
t.position += new Vector3( 0f, offsetY, 0f );
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613200411im_/https://answers.unity.com/themes/thub/images/avi.jpg)