- Home /
place object on a surface in editor
Hi there, I have a lot of levels to build by dragging & dropping prefabs from the project pane to the editor. These assets are balls that have their pivots at the center. However, i'd like to place them on top of a surface and they're always half stuck in the ground when I move them on the surface so I always have to incase the Y position for each object i drag in.
Is there a way to place the objects on the surface without being stuck?
Answer by DaveA · Dec 12, 2011 at 09:25 PM
Make a script, and set it to run in Edit mode: http://unity3d.com/support/documentation/ScriptReference/ExecuteInEditMode.html
In the Start function, set the Y position. If you just have a flat plane, it would be a constant, but if it's a variable surface, you can cast a ray down to find the floor.
Attach it to your prefab.
Have this just run in the editor. You can comment it out or remove it for run-time. But it should help you with initial placement.
almost perfect. however, i have to run the game at least once in order to place all orbs on top of the plane. this isn't too bad but i'd like to see them in their final position immediately without starting the game
Answer by Bryan-Legend · Oct 25, 2014 at 11:32 PM
While this doesn't help with the object being placed in the center, the editor supports surface snapping. I'm repeating it here because it's a bit hard to find and remember.
Surface Snapping
While dragging in the center using the Translate Tool, you can hold Shift and Control (Command on Mac) to snap the object to the intersection of any Collider. This makes precise positioning of objects incredibly fast.
Thanks. It is super hard to find this knowledge unless you already know the ter$$anonymous$$ology.
If someone DID want to snap to center and this IS based on colliders, colliders allow you to choose size and center so in theory....you could quickly add a small collider when its time to center, snao to it, then delete it(or disable it in case it happens again).
Answer by Antoon · Mar 04, 2017 at 09:10 AM
Most helpfull thing for that is the Vertex Snap:
Hold V will change the transform point to the nearest Vertex to the mouse cursor - and then snap all movements to vertices on other objects
Your answer
Follow this Question
Related Questions
Placing assets by clicking in the editor? 0 Answers
increasing scale based on mouse position 0 Answers
How to Massplace Assets with Script at Edittime 1 Answer
Placing items on terrain in the editor 3 Answers